feat: integrate sentry in main and renderer process#410
Conversation
0b6235c to
956805e
Compare
There was a problem hiding this comment.
I've tried to get the app version using version.ts and applying some changes to the scripts.js in the UI build but always resulted in undefined values. Any suggestions to get the version for the renderer process? 🙏
There was a problem hiding this comment.
That's because it's running in the renderer process, and since we have context isolation enabled and node integration disabled, you cannot access to version.ts code.
However, you should have access to the electronBridge api within the window object, which provides a desktopVersion() method that returns a promise to the current version via the context bridge.
So something like this might work:
window.electronBridge.desktopVersion().then((version: string) => {
global.sentry = setupSentry({
release: version,
}
})
I'm not sure if this file should go here or in the ui folder. It's difficult to judge.
There was a problem hiding this comment.
If we stop calling the renderer version of setupSentry from lavamoat.ts, we could move both these files to the ui folder, although I'm not sure if typescript is supported there.
There was a problem hiding this comment.
Brilliant! I will try using the Context Bridge.
I also had the same thought about moving it to UI folder but I didn't get @sentry/electron working with the main and renderer process so in the end, I had to split and call the main process into lavamoat.ts.
I could explore more alternatives to that but without initializing the main process the renderer process stop working 😞.
956805e to
91faa3a
Compare
91faa3a to
a1b5917
Compare
packages/app/src/app/lavamoat.ts
Outdated
There was a problem hiding this comment.
If sentry-install.js is injected even before compiled javascript bundles, do we still need to initiate Sentry here?
There was a problem hiding this comment.
Oh nvm, sentry-install.js is not initiating Sentry at all.
There was a problem hiding this comment.
It is. sentry-install.js calls setupSentry, which in turn calls Sentry.init(...).
Also we are already initialising Sentry in globals.ts, so we shouldn't initialise it here as well.
There was a problem hiding this comment.
Yes, that's true @bergarces, I don't know why did I make my second comment :/
There was a problem hiding this comment.
We have two sentries running now one from the extension covering background and extension UI and the Desktop app covering renderer and main processes.
There was a problem hiding this comment.
But I think we have three right now.
- One that runs in the renderer process when the
sentry-install.jsruns. - One that runs in the main process when you call
Sentry.inithere inlavamoat.ts. - One that also runs in the main process when
globals.tsis loaded here, which also runsSentry.initwith the same settings as the extension (since that one deals with the extension state and needs the filtering from the extensionsentrySetup).
My argument is that we don't need the second here, we can just add that ipcMode: Sentry.IPCMode.Both to the one we are already initialising in the main process.
EDIT: Ok, this has to do with the fact the extension one might not be loaded if they have not agreed with sharing in the extension. I get it now.
d9d639f to
e9b42ec
Compare
04d3924 to
f144136
Compare
packages/app/src/app/lavamoat.ts
Outdated
There was a problem hiding this comment.
I'm not sure what the ipcMode does, but it should be added through globals.ts Sentry initialisation.
The problem is that globals.ts calls the setupSentry.js from the extension. So you'd have to do something hacky such as hijacking the Sentry object we pass, and make it so that the Sentry.init(something) is a shim that calls (something) => Sentry.init({ ...something, ipcMode: Sentry.IPCMode.Both })
9dd4a53 to
2832209
Compare
67bfe37 to
dd1338b
Compare
There was a problem hiding this comment.
This is the renderer process Sentry setup. Nothing is sent through here yet as the errors are bubbling up to the main process.
We can worry about getting the filter right then.
packages/app/src/app/globals.ts
Outdated
There was a problem hiding this comment.
This will need to be simplified when readPersistedSettingFromAppState returns boolean from the state.
packages/app/src/app/globals.ts
Outdated
There was a problem hiding this comment.
As discussed:
- Desktop opt in must be enabled to send Sentry reports through desktop, always.
- If
desktopEnabledexists and it is truthy, then we also need for the extension opt in to be true.
packages/app/build/ui/scripts.js
Outdated
There was a problem hiding this comment.
We had to restore some of the values so that they can be used in the sentry-install script for the renderer process.
1f35039 to
9cea1da
Compare
There was a problem hiding this comment.
I've got rid of the distinction between SENTRY_DSN_DEV and SENTRY_DSN that they use in the extension.
We can control if we pass a dev or a prod one in the CI pipeline.
a6ca5d2 to
7986a39
Compare
7986a39 to
6d64ed3
Compare
Overview
The aim of this PR is to integrate sentry into the renderer process.
It's required to initialize the main process in order to have the renderer process integrated and capture/send the errors, also both need to be run outside lavamoat.
Changes
scripts.js: added the normal bundle to support sentry in UI builddesktop-ui.html: added sentry-install script before lavamoat as done in the extension.lavamoat.tsgetSentryDefaultOptions()is used on the main and renderer processes to make sure both are going to be initialized otherwise sentry won't work.Others
In order to test Sentry locally:
Create a Sentry account using your consensys email address so that it gets automatically added to the consensys organization.
Add a new javascript project.
Access project settings -> SDK Setup -> Client Keys (DSN)
Copy the DSN into environment variables in .metamaskrc called
SENTRY_DSN_DEVandSENTRY_DSN.Example of custom error from the render react components:

Example of custom error from the renderer process:

Example of custom error from the main process:

Issues
resolves: #199