Call Sentry.init() as early as possible — before any other application code runs.
import * as Sentry from "@sentry/browser";Sentry.init({ dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", environment: "production", release: "my-app@1.0.0", tracesSampleRate: 1.0, replaysSessionSampleRate: 0.1, replaysOnErrorSampleRate: 1.0,});
For Node.js, import instrument.js at the very top of your entry point using --import ./instrument.js (ESM) or require('./instrument.js') (CJS) so Sentry initializes before any other modules load.
Context enriches events so you can filter and search in Sentry.
// Identify the current userSentry.setUser({ id: "42", email: "user@example.com" });// Add a searchable tagSentry.setTag("section", "checkout");// Add arbitrary extra data (not indexed)Sentry.setExtra("orderId", "12345");
Breadcrumbs are a trail of events captured before an error occurs. Sentry automatically records navigation, console output, XHR requests, and DOM clicks. You can also add custom breadcrumbs:
For automatic instrumentation of fetch, XMLHttpRequest, and browser navigation, include the BrowserTracing integration (built into @sentry/browser in SDK v8+):
import * as Sentry from "@sentry/browser";Sentry.init({ dsn: "https://examplePublicKey@o0.ingest.sentry.io/0", integrations: [Sentry.browserTracingIntegration()], tracesSampleRate: 1.0,});