Sentry initialization tuned to your platform
Sentry is configured through a single Sentry.init() call, but the right package, integrations, and sample rates differ between a browser app and a Node service. This tool builds the snippet for your platform with the integrations that make sense there.
How it works
The init call takes a dsn that routes events to your project, plus environment and release tags that let you filter and attribute errors to a deploy. Integrations extend the SDK: browserTracingIntegration automatically instruments page loads and navigations for performance data, while replayIntegration records DOM mutations into a session replay. Both are browser-only, so the builder omits them for Node platforms.
Sampling is controlled by rates between 0 and 1. tracesSampleRate is the fraction of transactions kept for performance monitoring. For replay there are two knobs: replaysSessionSampleRate captures a slice of all sessions, and replaysOnErrorSampleRate captures sessions that produced an error — usually set to 1.0 so every crash is recorded. Finally, beforeSend is a hook invoked on each event; returning the event sends it, returning null drops it, which is the standard way to filter benign noise or scrub sensitive fields.
Tips and example
Keep the traces rate low in production to protect quota, and rely on the on-error replay rate to guarantee crashes are captured. A React setup:
import * as Sentry from "@sentry/react";
Sentry.init({
dsn: "https://[email protected]/0",
environment: "production",
release: "[email protected]",
integrations: [Sentry.browserTracingIntegration(), Sentry.replayIntegration()],
tracesSampleRate: 0.1,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});
Upload source maps in CI with your Sentry auth token so stack traces map back to readable source instead of minified bundles.