Skip to content

Commit

Permalink
chore: improve bug reporting data (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente authored Jul 10, 2023
1 parent b273ac5 commit 6c9222b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import React from 'react';
// skipcq: JS-C1003 - sentry does not expose itself as an ES Module.
import * as Sentry from '@sentry/react';

import { runtime } from '@/common/stores/runtime';
import { hasConnected, reconnectAttempts, shouldReconnect } from '@/common/utils/socket';

import style from './ErrorBoundary.module.scss';

class ErrorBoundary extends React.Component {
Expand All @@ -25,7 +28,9 @@ class ErrorBoundary extends React.Component {
});

Sentry.withScope((scope) => {
scope.setExtras(error);
scope.setExtras('error', error);
scope.setExtras('store', runtime.getState());
scope.setExtras('hasSocket', { hasConnected, shouldReconnect, reconnectAttempts });
const eventId = Sentry.captureException(error);
this.setState({ eventId, info });
});
Expand Down
8 changes: 6 additions & 2 deletions apps/client/src/common/utils/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import { runtime } from '../stores/runtime';
export let websocket: WebSocket | null = null;
let reconnectTimeout: NodeJS.Timeout | null = null;
const reconnectInterval = 1000;
let shouldReconnect = true;

export let shouldReconnect = true;
export let hasConnected = false;
export let reconnectAttempts = 0;
export const connectSocket = () => {
websocket = new WebSocket(websocketUrl);

websocket.onopen = () => {
clearTimeout(reconnectTimeout as NodeJS.Timeout);
hasConnected = true;
reconnectAttempts = 0;
};

websocket.onclose = () => {
Expand All @@ -23,6 +26,7 @@ export const connectSocket = () => {
reconnectTimeout = setTimeout(() => {
console.warn('WebSocket: attempting reconnect');
if (websocket && websocket.readyState === WebSocket.CLOSED) {
reconnectAttempts += 1;
connectSocket();
}
}, reconnectInterval);
Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Sentry.init({
tracesSampleRate: 1.0,
release: ONTIME_VERSION,
enabled: import.meta.env.PROD,
ignoreErrors: ['top.GLOBALS', 'Unable to preload CSS'],
denyUrls: [/extensions\//i, /^chrome:\/\//i, /^chrome-extension:\/\//i],
});

root.render(
Expand Down

0 comments on commit 6c9222b

Please sign in to comment.