electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
903 stars 170 forks source link

Sentry integration not working #437

Closed komyg closed 2 years ago

komyg commented 3 years ago

Hi,

I am creating an app using Electron Webpack and Electron builder for Windows and Mac. However I am having some trouble adding Sentry to the Electron main process.

I've added the @sentry/electron package and configured using Sentry Init in the main file:

import * as Sentry from '@sentry/electron';

Sentry.init({
  dsn: 'https://12345676@mysentry.io/1234',
});

But It is not capturing exceptions messages.

I am also using electron-log to capture and log exceptions, but this hasn't work either:

import log from 'electron-log';

log.catchErrors({
  onError: (error) => {
    Sentry.captureException(error);
  },
  showDialog: true,
});

Has anyone been through this? I think that this might be some configuration issue.

Thanks, Komyg

shahkeyur commented 3 years ago

I have been using sentry for a while with electron now. I had an issue that sentry wasn't sending reports if use sentry.close method.

Try putting a timeout for 3 seconds before shutdown. Or else you should try to import from /dist/main.

I am not sure if this is a configuration issue, I dont think that it should be.

loopmode commented 3 years ago

I'm not sure about this, but it seems to me that your setup would only capture errors in the main process. Are you trying to capture errors in the renderer process instead?

komyg commented 3 years ago

Hey @shahkeyur, thank you for the tips. I did try to import from /dist/main, but it didn't work.

I also called Sentry.flush() after sending a few messages to force Sentry, but it also didn't work. However, I didn't manage to delay the app shutdown, but since I called flush I think I don't need to.

shahkeyur commented 3 years ago

Have you put app.exit in flush callback? If so, try putting timeout before exit.

shahkeyur commented 3 years ago

If you can link to a repository, may be I can help.

komyg commented 3 years ago

I'm not sure about this, but it seems to me that your setup would only capture errors in the main process. Are you trying to capture errors in the renderer process instead?

No, I am trying to capture errors on the main process. I've added sentry browser for the renderer process in an independent setup.

loopmode commented 3 years ago

Ok, was just making sure :)

komyg commented 3 years ago

If you can link to a repository, may be I can help.

Sorry, this repo is not open source, so I can't share it with you.

komyg commented 3 years ago

I did manage to make some progress. I changed my import from @sentry/electron to @sentry/node for the main process and it worked, I got the events.

Here is my config code, which is called as soon as the apps starts:

import * as Sentry from '@sentry/node';
import { IS_DEVELOPMENT, VERSION } from './settings';

export function configSentry(): void {
  if (!IS_DEVELOPMENT) {
    Sentry.init({
      dsn: 'https://12346@sentry.mydomain/1',
      release: VERSION,
    });
  }
}

But I think that ideally I should use the @sentry/electron instead of the @sentry/node right?

timfish commented 3 years ago

@sentry/electron merges scope and breadcrumbs from all processes in the main process and reports native crashes from all processes with context too.

You won't get any of that if you use @sentry/node

You need to call @sentry/electron init in all processes including preload if you're using context isolation.

If any of the above doesn't work with the latest version, please open an issue on the Sentry repo and include a reproduction repository showing any issues and I'll be happy to take a look!