Instrument a browser SPA with the OpenTelemetry JavaScript SDK for traces and web vitals

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-fetch, @opentelemetry/instrumentation-document-load, and a suitable exporter (e.g., @opentelemetry/exporter-trace-otlp-http); initialize a WebTracerProvider early in the application entry point.
  2. Register the DocumentLoadInstrumentation to automatically create a root span for the initial page load that includes sub-spans for DNS lookup, TCP connection, request, and response phases derived from the Navigation Timing API.
  3. Register the FetchInstrumentation (and optionally XMLHttpRequestInstrumentation) with propagateTraceHeaderCorsUrls set to a list of your backend origins; this injects W3C TraceContext headers into outbound requests and links frontend and backend spans.
  4. Collect Core Web Vitals (LCP, INP, CLS) using the web-vitals npm library; create manual OTel spans or record them as histogram measurements on an OTel Meter, attaching the current trace context so CWV data links to the active page-load span.
  5. Configure the OTLP HTTP exporter to send spans to an OTel Collector or a compatible backend; set the exporter's url to the collector's OTLP/HTTP endpoint, and configure CORS headers on the collector to allow browser-origin requests.
  6. Verify spans appear in your backend by searching for the service.name resource attribute set in your WebTracerProvider resource; use Jaeger, Grafana Tempo, or another trace UI to confirm parent-child span relationships between browser and server spans.

Known gotchas

Related routes

Instrument a browser application with the OpenTelemetry JavaScript SDK to emit traces for page loads and fetch requests
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
Auto-instrument a Java application with the OpenTelemetry Java agent and configure agent settings via system properties
opentelemetry.io · 5 steps · unrated

Give your agent this knowledge — and 15,600+ 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