Default Integrations

The Sentry Electron SDK uses @sentry/node in the main process and @sentry/browser in the renderers.

A number of integrations are included by default that setup communication between Electrons multiple processes and include Electron specific context and breadcrumbs.

Main Process

MainContext

Adds app, operating system and runtime context to all events.

OnUncaughtException

Supports capturing events from uncaughtException while retaining Electrons default behaviour of displaying an error dialog if there are no other listeners.

To disable Electrons default error dialog, simply add another listener:

Copied
process.on("uncaughtException", () => {});

ElectronBreadcrumbs

Captures breadcrumbs for events for many of Electrons built-in modules. The breadcrumbs captured for each module can be configured true to capture all events or false to capture no events. Alternatively you can supply a function which is passed the event name and returns true or false depending on whether the event should be captured.

The defaults for this integration are effectively:

Copied
import * as Sentry from "@sentry/electron";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [
    Sentry.Integrations.ElectronBreadcrumbs({
      app: (name) => !name.startsWith("remote-"),
      autoUpdater: true,
      webContents: (name) =>
        ["dom-ready", "context-menu", "load-url", "destroyed"].includes(name),
      browserWindow: (name) =>
        [
          "closed",
          "close",
          "unresponsive",
          "responsive",
          "show",
          "blur",
          "focus",
          "hide",
          "maximize",
          "minimize",
          "restore",
          "enter-full-screen",
          "leave-full-screen",
        ].includes(name),
      screen: true,
      powerMonitor: true,
    }),
  ],
});

SentryMinidump

Captures minidumps and sends them with full context to the Sentry Envelope endpoint using a custom uploader.

PreloadInjection

Injects a preload script via the Electron session.setPreloads(preloads) API. By default sessions are only injected into the defaultSession. If you are using other sessions, you can pass a function as getSessions to init.

Copied
import { session } from "electron";
import * as Sentry from "@sentry/electron";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  getSessions: () => [
    session.defaultSession,
    session.fromPartition("persist:my-session"),
  ],
});

AdditionalContext

Adds additional device context to events.

The constructor takes a number of options which all default to true:

Copied
interface AdditionalContextOptions {
  cpu: boolean;
  screen: boolean;
  memory: boolean;
  language: boolean;
}

To disable specific context items, set them as false:

Copied
import * as Sentry from "@sentry/electron";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [
    Sentry.Integrations.AdditionalContext({
      screen: false,
    }),
  ],
});

Net

Captures breadcrumbs and

tracingThe process of logging the events that took place during a request, often across multiple services.
spans for Electrons net module. By default breadcrumbs and tracing spans are enabled and sentry-trace headers are added to requests for all origins.

The integration can be configured via constructor options:

Copied
interface NetOptions {
  /**
   * Whether breadcrumbs should be captured for net requests
   *
   * Defaults to: true
   */
  breadcrumbs: boolean;
  /**
   * Whether to capture transaction spans for net requests
   *
   * Defaults to: true
   */
  tracing: boolean | (method: string, url: string) => boolean;
  /**
   * Whether to add 'sentry-trace' headers to outgoing requests
   *
   * Defaults to: true
   */
  tracingOrigins: boolean | (method: string, url: string) => boolean;
}

For example, to disable breadcrumb capture and addition of sentry-trace headers and only capture spans for POST requests:

Copied
import * as Sentry from "@sentry/electron";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [
    Sentry.Integrations.Net({
      breadcrumbs: false,
      tracing: (method) => method == "POST",
      tracingOrigins: false,
    }),
  ],
});

ChildProcess

Captures breadcrumbs and events for child process exits and crashes.

Copied
type ExitReason =
  | "clean-exit"
  | "abnormal-exit"
  | "killed"
  | "crashed"
  | "oom"
  | "launch-failed"
  | "integrity-failure";

interface ChildProcessOptions {
  /** Child process events that generate Sentry breadcrumbs */
  breadcrumbs: ExitReason[];
  /** Child process events that generate Sentry events */
  events: ExitReason[];
}

For example, to disable capture of breadcrumbs and only capture events for Out-Of-Memory crashes:

Copied
import * as Sentry from "@sentry/electron";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [
    Sentry.Integrations.ChildProcess({
      breadcrumbs: [],
      capture: ["oom"],
    }),
  ],
});

MainProcessSession

Captures sessions linked to the lifetime of the Electron main process. These sessions result in release health statistics being displayed in Sentry.

Unless autoSessionTracking is set to false, this integration will be automatically added.

Copied
import * as Sentry from "@sentry/electron";

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  autoSessionTracking: false,
});

Renderer Process

ScopeToMain

Captures scope updates and breadcrumbs in renderer processes and forwards them to the Electron main process.

EventToMain

Captures events in the renderer processes and forwards them to the Electron main process. This integration prevents events from being sent by the underlying @sentry/browser SDK.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").