Skip to main content
The ClickStack browser SDK builds on OpenTelemetry to collect browser requests, errors, and session replay. Use it to investigate frontend events alongside your backend telemetry in ClickHouse Observability.

Install

Install the package in your frontend application:
The package uses ES modules. npm installs its OpenTelemetry peer dependencies automatically. If your application also installs @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

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:
Call 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 for my-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 to init. 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 the rr-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:
When you’re ready to resume recording:

Link frontend and backend traces

To connect browser requests to backend traces, add traceOrigins to your init options, replacing the example with your backend origin:
Requests to the page’s own origin and matching backends carry 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, use setUser to attach user information to subsequent spans and logs:
On sign-out, clear the user information and start a new session:
To attach application metadata to subsequent spans and logs, use setAttributes. Each call replaces the previous set; pass null to clear it:
Uncaught errors and unhandled rejections are captured automatically. React error boundaries that report through 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:
Replace 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.