Skip to main content

[Electron] Which Sentry SDK do I use in a React Electron app?

Issue

I have a React app packaged with Electron and I need to know whether to install @sentry/react, @sentry/electron, or both.

Applies To

  • All SaaS Customers and Self-Hosted Users

  • Electron SDK (@sentry/electron)

  • React SDK (@sentry/react)

  • SDK Setup

Resolution

Use both packages. Install @sentry/electron for the Electron main and renderer processes. Install @sentry/react as well, and pass React's init into the Electron renderer init so React features work in the UI.

Do not call @sentry/react init on its own in an Electron renderer. That skips Electron IPC, native crash handling, and main-process capture.

Do not replace @sentry/electron with @sentry/node or @sentry/browser. Import @sentry/electron/main and @sentry/electron/renderer.

  1. Install @sentry/electron and @sentry/react.

  2. Call init from @sentry/electron/main in the main process, as early as possible.

  3. In each React renderer, call init from @sentry/electron/renderer and pass React's init as the second argument.

import * as Sentry from "@sentry/electron/main";Sentry.init({
  dsn: "https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
});

import { init } from "@sentry/electron/renderer";
import { init as reactInit } from "@sentry/react";init(
  {
    // dsn, release, and environment on renderer init have no effect.
    // Renderer events go through the main process.
    integrations: [
      /* integrations */
    ],
  },
  reactInit,
);

Did this answer your question?