Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

feat: integrate sentry in main and renderer process#410

Merged
bergarces merged 20 commits intomainfrom
199-add-sentry-integration-to-renderer-process
Jan 27, 2023
Merged

feat: integrate sentry in main and renderer process#410
bergarces merged 20 commits intomainfrom
199-add-sentry-integration-to-renderer-process

Conversation

@vinistevam
Copy link
Copy Markdown
Contributor

@vinistevam vinistevam commented Jan 13, 2023

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 build
  • desktop-ui.html: added sentry-install script before lavamoat as done in the extension.
  • started sentry main process in lavamoat.ts
  • getSentryDefaultOptions() 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_DEV and SENTRY_DSN.

Example of custom error from the render react components:
image

Example of custom error from the renderer process:
image

Example of custom error from the main process:
image

Issues

resolves: #199

@vinistevam vinistevam force-pushed the 199-add-sentry-integration-to-renderer-process branch 2 times, most recently from 0b6235c to 956805e Compare January 16, 2023 08:26
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? 🙏

Copy link
Copy Markdown
Contributor

@bergarces bergarces Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😞.

@vinistevam vinistevam force-pushed the 199-add-sentry-integration-to-renderer-process branch from 956805e to 91faa3a Compare January 16, 2023 08:40
@vinistevam vinistevam marked this pull request as ready for review January 16, 2023 08:51
@vinistevam vinistevam requested a review from a team January 16, 2023 08:51
@vinistevam vinistevam force-pushed the 199-add-sentry-integration-to-renderer-process branch from 91faa3a to a1b5917 Compare January 16, 2023 09:07
Copy link
Copy Markdown
Member

@OGPoyraz OGPoyraz Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If sentry-install.js is injected even before compiled javascript bundles, do we still need to initiate Sentry here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nvm, sentry-install.js is not initiating Sentry at all.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's true @bergarces, I don't know why did I make my second comment :/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two sentries running now one from the extension covering background and extension UI and the Desktop app covering renderer and main processes.

Copy link
Copy Markdown
Contributor

@bergarces bergarces Jan 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think we have three right now.

  • One that runs in the renderer process when the sentry-install.js runs.
  • One that runs in the main process when you call Sentry.init here in lavamoat.ts.
  • One that also runs in the main process when globals.ts is loaded here, which also runs Sentry.init with the same settings as the extension (since that one deals with the extension state and needs the filtering from the extension sentrySetup).

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.

@vinistevam vinistevam force-pushed the 199-add-sentry-integration-to-renderer-process branch from d9d639f to e9b42ec Compare January 16, 2023 10:39
@vinistevam vinistevam force-pushed the 199-add-sentry-integration-to-renderer-process branch 4 times, most recently from 04d3924 to f144136 Compare January 17, 2023 14:23
Copy link
Copy Markdown
Contributor

@bergarces bergarces Jan 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 })

@vinistevam vinistevam force-pushed the 199-add-sentry-integration-to-renderer-process branch 2 times, most recently from 9dd4a53 to 2832209 Compare January 20, 2023 08:32
@bergarces bergarces force-pushed the 199-add-sentry-integration-to-renderer-process branch 4 times, most recently from 67bfe37 to dd1338b Compare January 25, 2023 14:00
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be simplified when readPersistedSettingFromAppState returns boolean from the state.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed:

  • Desktop opt in must be enabled to send Sentry reports through desktop, always.
  • If desktopEnabled exists and it is truthy, then we also need for the extension opt in to be true.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had to restore some of the values so that they can be used in the sentry-install script for the renderer process.

@bergarces bergarces force-pushed the 199-add-sentry-integration-to-renderer-process branch 3 times, most recently from 1f35039 to 9cea1da Compare January 25, 2023 14:53
Copy link
Copy Markdown
Contributor

@bergarces bergarces Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bergarces bergarces force-pushed the 199-add-sentry-integration-to-renderer-process branch from a6ca5d2 to 7986a39 Compare January 27, 2023 09:05
@bergarces bergarces force-pushed the 199-add-sentry-integration-to-renderer-process branch from 7986a39 to 6d64ed3 Compare January 27, 2023 09:15
@bergarces bergarces merged commit 744f407 into main Jan 27, 2023
@vinistevam vinistevam deleted the 199-add-sentry-integration-to-renderer-process branch February 1, 2023 08:02
@cryptotavares cryptotavares mentioned this pull request Mar 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Sentry integration to renderer process

3 participants