-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: enable Sentry in renderer process #397
base: main
Are you sure you want to change the base?
Conversation
…studio into feat/crash-reporter-settings
src/renderer.ts
Outdated
integrations: [ | ||
Sentry.browserTracingIntegration(), | ||
Sentry.replayIntegration(), | ||
], | ||
tracesSampleRate: 1.0, | ||
replaysSessionSampleRate: 0.1, | ||
replaysOnErrorSampleRate: 1.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabled some basic integrations such as browser tracing and session replay, which may help us debug issues when they arise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we consider filtering events to scrub sensitive data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unhandled promise rejections are not reported to sentry, to reproduce it: add a throw to an async method, I've used validateAndSaveHarFile
in views/Recorder/Recorder.tsx
.
I've skimmed through docs and looks like sentry/react
integration should handle this automatically if we add it additionally to sentry/electron
, here's an example how to setup additional SDK: https://docs.sentry.io/platforms/javascript/guides/electron/#framework-specific-sdks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@e-fisher Unfortunately @sentry/react
didn't work and after spending some time trying to figure out why I learned the following.
The unhandled rejection gets raised inside the callback of the onBrowserClosed
subscription, which is where validateAndSaveHarFile
is being called.
k6-studio/src/views/Recorder/Recorder.tsx
Lines 153 to 155 in 898bde8
useEffect(() => { | |
return window.studio.browser.onBrowserClosed(async () => { | |
const fileName = await validateAndSaveHarFile() |
However, onBrowserClosed
is declared in the preload context (not in the main renderer
).
Electron creates two separate environments for the renderer process: the main renderer and the preload script. Sentry was only initialized in the renderer.ts
file, which prevented it from capturing errors originating from functions or callbacks within the preload
context.
The problem was solved by:
- initializing Sentry in the preload and renderer contexts
- adding an event listener for
unhandledrejection
to catch unhandled promise rejections
|
||
// conditionally send the event based on the user's settings | ||
beforeSend: async (event) => { | ||
const getSettings = getSettingsFn || window.studio.settings.getSettings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window
isn't available in the preload context so I'm adding flexibility here to pass the getSettings function as an argument optionally.
Description
This PR enables the Sentry integration in the renderer process, accounting for the user's preference to opt out of it. This PR is dependant on #393.
How to Test
main.ts
andrenderer.ts
)SENTRY_DSN
env variable set (grab it from the project in Sentry)SENTRY_DSN=xx npm start
Checklist
npm run lint
) and all checks pass.npm test
) and all tests pass.Screenshots (if appropriate):
Related PR(s)/Issue(s)
Resolves #396