Skip to content

Commit ca69237

Browse files
christianalfoniCompuIves
authored andcommitted
send actions as breadcrumbs to sentry (codesandbox#3117)
1 parent 8420108 commit ca69237

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

packages/app/src/app/index.js

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import {
1111
initializeSentry,
1212
logError,
1313
} from '@codesandbox/common/lib/utils/analytics';
14+
import { logBreadcrumb } from '@codesandbox/common/lib/utils/analytics/sentry';
1415
import _debug from '@codesandbox/common/lib/utils/debug';
1516
import {
1617
convertTypeToStatus,
1718
notificationState,
1819
} from '@codesandbox/common/lib/utils/notifications';
1920
import { isSafari } from '@codesandbox/common/lib/utils/platform';
21+
import { Severity } from '@sentry/browser';
2022
import { client } from 'app/graphql/client';
2123
import history from 'app/utils/history';
2224
import { createOvermind } from 'overmind';
@@ -43,16 +45,6 @@ window.addEventListener('unhandledrejection', e => {
4345
}
4446
});
4547

46-
if (process.env.NODE_ENV === 'production') {
47-
try {
48-
initializeSentry(
49-
'https://[email protected]/155188'
50-
);
51-
} catch (error) {
52-
console.error(error);
53-
}
54-
}
55-
5648
window.__isTouch = !matchMedia('(pointer:fine)').matches;
5749

5850
const overmind = createOvermind(config, {
@@ -66,6 +58,48 @@ const overmind = createOvermind(config, {
6658
logProxies: true,
6759
});
6860

61+
if (process.env.NODE_ENV === 'production') {
62+
const ignoredOvermindActions = [
63+
'onInitialize',
64+
'server.onCodeSandboxAPIMessage',
65+
'track',
66+
'editor.previewActionReceived',
67+
'live.onSelectionChanged',
68+
];
69+
70+
try {
71+
initializeSentry(
72+
'https://[email protected]/155188'
73+
);
74+
75+
overmind.eventHub.on('action:start', event => {
76+
if (ignoredOvermindActions.includes(event.actionName)) {
77+
return;
78+
}
79+
80+
// We try as the payload might cause a stringify error
81+
try {
82+
logBreadcrumb({
83+
category: 'overmind-action',
84+
message: event.actionName,
85+
level: Severity.Info,
86+
data: {
87+
value: JSON.stringify(event.value),
88+
},
89+
});
90+
} catch (e) {
91+
logBreadcrumb({
92+
category: 'overmind-action',
93+
message: event.actionName,
94+
level: Severity.Info,
95+
});
96+
}
97+
});
98+
} catch (error) {
99+
console.error(error);
100+
}
101+
}
102+
69103
/*
70104
Temporary global functions to grab state and actions, related to old
71105
Cerebral implementation

packages/common/src/utils/analytics/sentry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Breadcrumb } from '@sentry/browser';
2+
23
import VERSION from '../../version';
34
import { DO_NOT_TRACK_ENABLED } from './utils';
45

@@ -35,6 +36,7 @@ export async function initialize(dsn: string) {
3536
"undefined is not an object (evaluating 'window.__pad.performLoop')", // Only happens on Safari, but spams our servers. Doesn't break anything
3637
],
3738
whitelistUrls: [/https?:\/\/((uploads|www)\.)?codesandbox\.io/],
39+
maxBreadcrumbs: 20,
3840
/**
3941
* Don't send messages from the sandbox, so don't send from eg.
4042
* new.codesandbox.io or new.csb.app

0 commit comments

Comments
 (0)