Skip to main content

Sentry Adapter

Send captured errors, messages, breadcrumbs, and user context to Sentry.

Install

yarn add @sentry/browser

Activate

import { initialize, useAdapter } from 'unified-error-handling';

initialize();

await useAdapter('sentry', {
dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
environment: 'production',
release: '1.4.2',
});

Config

Pass the options your Sentry project expects. The most common:

FieldPurpose
dsnYour Sentry project DSN (required).
environmentEnvironment label (e.g. production).
releaseRelease identifier for grouping.

The adapter forwards your config to the Sentry SDK on initialize, then maps each NormalizedError, message, breadcrumb, and context update onto the corresponding Sentry call.

Notes

  • The @sentry/browser SDK is loaded with a dynamic import() only when you activate this adapter — it never reaches a bundle that does not use Sentry.
  • If @sentry/browser is not installed, activation throws Failed to load Sentry SDK… with the original import error preserved as cause.
  • Use the store's beforeSend hook (in initialize()) to scrub PII before it reaches Sentry.

See the adapters guide for switching and the core API for setUser / addBreadcrumb, which the adapter forwards.