Browser
<!-- status: beta language: browser -->
Browser
Send traces from a web page with the OpenTelemetry web SDK over OTLP/HTTP. A page cannot read environment variables, so the endpoint and key are set in code.
Create a project, then an ingestion key (
wti_...) with theingest:tracesscope.Install the SDK and run this once at page start:
npm install @opentelemetry/sdk-trace-web @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-httpimport { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
const exporter = new OTLPTraceExporter({
url: 'https://ingest.example.com/v1/traces',
headers: { 'x-watchtower-key': 'wti_YOUR_KEY' },
});
const provider = new WebTracerProvider({ spanProcessors: [new BatchSpanProcessor(exporter)] });
provider.register();
provider.getTracer('onboarding').startSpan('hello-watchtower').end();The onboarding screen polls
GET /v1/projects/{prj}/onboarding/first-eventand turns green when the first span arrives.
A key in page source is public. Use a key scoped to the one signal you need and expect it to be copied; publishable browser keys with an origin allowlist arrive with the browser SDK (sdks/browser). Until then use this for development, or send through your own backend.
Updated