Instrument a browser application with the OpenTelemetry JavaScript SDK to emit traces for page loads and fetch requests

domain: opentelemetry.io · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Install @opentelemetry/sdk-trace-web, @opentelemetry/instrumentation-document-load, @opentelemetry/instrumentation-fetch, and @opentelemetry/exporter-trace-otlp-http
  2. Create a WebTracerProvider, register the OTLPTraceExporter pointing at your collector's OTLP/HTTP endpoint, and add a BatchSpanProcessor for efficient batching
  3. Register DocumentLoadInstrumentation and FetchInstrumentation (optionally XMLHttpRequestInstrumentation) via registerInstrumentations so that automatic spans are created for navigation and network calls
  4. Configure propagateTraceHeaderCorsUrls in FetchInstrumentation to specify which origins should receive traceparent and tracestate headers; backends must include these in CORS Access-Control-Allow-Headers
  5. Call provider.register() to activate the global tracer, then acquire a tracer with opentelemetry.trace.getTracer('app-name') for manual span creation in critical user interactions
  6. Verify spans appear in your backend trace store (e.g., Tempo or Jaeger) by matching the trace ID logged in the browser console with the root span in the trace UI

Known gotchas

Related routes

Instrument a browser SPA with the OpenTelemetry JavaScript SDK for traces and web vitals
opentelemetry.io · 6 steps · unrated
Capture and export browser errors and web vitals as OTel spans using the OTel JS SDK with custom instrumentation
opentelemetry.io · 6 steps · unrated
Emit and ingest the experimental OpenTelemetry profiling signal using the OTel Collector and Pyroscope exporter
opentelemetry.io · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans