Install
Install the package in your frontend application:@opentelemetry/api directly, use version ~1.9.1 and keep a single copy; version 1.10 is outside this SDK’s supported range.
Configure your destination
- Fully managed
- Self-managed
Open Team Settings → Data → Managed Telemetry in your service and copy the OTLP HTTP endpoint and API key. Use the complete HTTPS endpoint, including its port, without a signal path such as
/v1/traces.Initialize the SDK in your application’s entry module:init once per page load, at the top level of your entry module, such as src/main.ts in Vite or instrumentation-client.ts in Next.js. Initialization runs asynchronously; requests made immediately in the same tick may not be captured. Do not initialize in a React effect: cleanup that calls shutdown permanently stops telemetry for that page load.
Browser configuration is visible to anyone who loads the page, including its ingestion key. To keep the key on your server, use a same-origin endpoint such as
/otel, omit apiKey, and configure your server to forward the OTLP requests with the appropriate authorization header.Verify ingestion
Load your application, interact with the page, make a request, and emit a console error. In ClickHouse Observability, select a recent time range and search Logs or Traces formy-frontend-app. Open Session replay to inspect the recorded session.
If data is missing, inspect the browser console and network requests to /v1/traces and /v1/logs. Check the endpoint, authorization header, CORS, and Content Security Policy. For self-managed deployments, confirm that your ClickStack version supports replay and the SDK’s standard session.id attribute; receiving records alone does not confirm that sessions appear in the UI.
Initialization options
Pass these options toinit. Use endpoint for a shared collector, or provide both signal endpoints when traces and logs have separate destinations.
For the complete API, see the browser SDK reference.
Session replay and privacy
Session replay is enabled by default. Text and input values are masked by default. Masking does not hide checkbox states, radio states, or attributes such as link URLs and placeholders. Use therr-block class to exclude sensitive elements. URL sanitization does not cover URLs inside replayed page content, stack traces, or console messages. Only capture user information permitted by your privacy policy.
To pause replay without stopping browser telemetry:
Link frontend and backend traces
To connect browser requests to backend traces, addtraceOrigins to your init options, replacing the example with your backend origin:
traceparent, tracestate, and baggage. Your backend must be instrumented to continue that context.
Cross-origin backends must allow these headers through CORS. The telemetry collector must also permit the frontend origin. If your application uses Content Security Policy, allow the collector endpoint in connect-src.
Identify users and record errors
On sign-in, usesetUser to attach user information to subsequent spans and logs:
setAttributes. Each call replaces the previous set; pass null to clear it:
console.error are also captured by default. Use recordException for caught errors that are not already logged; recording and logging the same error creates duplicate events:
submitCheckout with the application operation you want to monitor.
Migrating from the HyperDX browser SDK
This is not a package-name-only upgrade.url becomes endpoint, service becomes serviceName, and tracePropagationTargets becomes traceOrigins. Text and input masking now default to true. Replace setGlobalAttributes with setUser for user identity and setAttributes for application metadata. React error boundaries that report through console.error need no extra hook; use recordException when an error is not already logged.
See the SDK migration guide for removed options and attribute changes. For a script-tag installation or an application that already initializes OpenTelemetry, see the SDK README.
If the ClickStack browser SDK causes a compatibility issue in your application, you can use the legacy HyperDX browser SDK while investigating it. Restore its configuration and API calls using the migration guide above; the two SDKs are not interchangeable and should not run together.