sentry-electron icon indicating copy to clipboard operation
sentry-electron copied to clipboard

documentation for attaching metadata for native crashes

Open nikitakot opened this issue 4 months ago • 2 comments

what's a correct way for attaching metadata for the native crashes when using @sentry/electron?

I use the following setup for adding additional information to the native crash event, so I know which app version crashed, not the version which uploaded the crash:

crashReporter.start({
  uploadToServer: false,
});

(async () => {
  const SentryEnv = import.meta.env.VITE_SENTRY_ENVIRONMENT;
  if (['testing', 'beta', 'production'].includes(SentryEnv))
    Sentry.init({
      dsn: 'sentry',
      sendDefaultPii: true,
      integrations: [eventLoopBlockIntegration({ threshold: 3000, maxEventsPerHour: 3 })],
    });
  // manually add version number, because Sentry attaches the version number of the app that uploads the crash report, which could be different from the version in which the crash happened
  crashReporter.addExtraParameter('appVersion', app.getVersion());

however I just tried using Sentry.setTag instead of crashReporter.addExtraParameter and it seems to work too, I'm pretty sure couple years ago when I was setting up crashReporter.addExtraParameter Sentry.setTag were getting lost, so are they now correctly attached and not overwritten by the uploading app session?

(async () => {
  const SentryEnv = import.meta.env.VITE_SENTRY_ENVIRONMENT;
  if (['testing', 'beta', 'production'].includes(SentryEnv))
    Sentry.init({
      dsn: 'sentry',
      sendDefaultPii: true,
      integrations: [eventLoopBlockIntegration({ threshold: 3000, maxEventsPerHour: 3 })],
    });
  // manually add version number, because Sentry attaches the version number of the app that uploads the crash report, which could be different from the version in which the crash happened
  Sentry.setTag('session-app-version', app.getVersion());

nikitakot avatar Oct 24 '25 10:10 nikitakot

ELECTR-36

linear[bot] avatar Oct 24 '25 10:10 linear[bot]

If you don't pass a specific release to init the SDK will default to appName@appVersion.

We have a test that ensures the correct app version is included when a native crash occurs in the previous version: https://github.com/getsentry/sentry-electron/tree/master/test/e2e/test-apps/native-sentry/main-update

You should not be calling crashReporter.start manually. Native crash handling is already enabled by the SDK here: https://github.com/getsentry/sentry-electron/blob/master/src/main/integrations/sentry-minidump/index.ts#L52

timfish avatar Oct 24 '25 10:10 timfish