0Pricing
React Academy · Lesson

Correlating Frontend and Backend Traces

Propagate trace context through fetch requests so backend spans appear under the same trace as the triggering UI action.

Correlating Frontend and Backend Traces is a free React Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the React Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Distributed Trace Goal

The ultimate goal of frontend observability is a single trace that connects a user's click in React through the network, through API handlers, through service calls, and down to the database query that caused a slow response. This end-to-end trace makes root cause analysis instant.

W3C TraceContext Standard

The W3C TraceContext specification defines the traceparent header format: version-traceId-parentSpanId-flags. A sample value looks like: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01. The trace ID is shared across the entire distributed trace; the parent span ID changes at each hop.

Automatic Header Injection

The OTel fetch instrumentation automatically injects the traceparent header into every outgoing fetch request. The header carries the current trace ID and the span ID of the frontend fetch span as the parent, allowing the backend to create a child span that is linked to the frontend span.

Backend Trace Continuation

On the server, the OTel HTTP instrumentation for Node.js/Express reads the incoming traceparent header and creates spans that are children of the frontend fetch span. The trace ID is preserved, so Jaeger or Grafana Tempo shows the entire chain — browser span → Express span → database span — in one waterfall view.

Viewing Traces in Jaeger or Grafana Tempo

With both frontend and backend instrumented, open Jaeger or Grafana Tempo and search for a trace ID. You'll see the full waterfall: the React component span at the top, the fetch span below it, then the Express route handler span, then the database query span — all with their durations and attributes.

Correlating by User

Set user.id as an attribute on all spans in your React app using span.setAttribute('user.id', userId). Do the same on the backend. Now you can filter your observability backend to show all traces for a specific user ID, enabling you to diagnose issues reported by a specific customer.

Correlating by Session

Generate a unique session ID on page load and set it as session.id on all frontend spans. Include it in request headers so the backend also attaches it to backend spans. Session correlation lets you reconstruct the complete sequence of actions a user took in a single session.

Linking RUM Sessions to Traces

Commercial tools like Datadog integrate RUM sessions with APM traces natively. The Datadog RUM SDK injects a specific header (X-Datadog-Trace-Id) into fetch requests, and the Datadog APM SDK on the backend reads it to link the RUM session replay to the distributed trace — you can watch the session replay and see the trace simultaneously.

The Correlation Payoff

Consider a user complaining that checkout is slow. With correlated traces, you search by user.id in your observability backend, find the checkout trace, and see immediately that the slowdown was a 900ms database query joining two large tables — something invisible to frontend metrics alone.

OpenTelemetry Collector as a Proxy

Browsers cannot send traces directly to Jaeger or other backends (CORS restrictions and credential exposure). Instead, run an OTel Collector as a proxy: configure OTLPTraceExporter to send to your Collector endpoint, which then fans out to Jaeger, Grafana Tempo, or any other backend.

Privacy Considerations

Frontend traces can inadvertently capture sensitive data: form field values in URLs, PII in span attributes, session tokens in headers. Review your instrumentation to ensure no sensitive data is included in span attributes. Use span.setAttribute sparingly and sanitize URL query parameters before recording them.

traceparent Header Format

What is the format of the W3C TraceContext traceparent header?

Lesson Recap

Correlating frontend and backend traces creates end-to-end visibility across the full user request journey. W3C TraceContext traceparent headers connect browser fetch spans to backend spans automatically via OTel instrumentation. Enrich all spans with user.id and session.id for targeted debugging. Use an OTel Collector as a browser-to-backend proxy to avoid CORS issues and credential exposure.

Frequently asked questions

Is the “Correlating Frontend and Backend Traces” lesson free?

Yes — the full text of “Correlating Frontend and Backend Traces” is free to read here on the web, and the React Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the React Academy course, upgrade to CoddyKit PRO.

What will I learn in “Correlating Frontend and Backend Traces”?

Propagate trace context through fetch requests so backend spans appear under the same trace as the triggering UI action. You practise React Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start React Academy?

No prior experience is required. React Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Correlating Frontend and Backend Traces” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this React Academy lesson?

Yes. Every React Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Frontend Observability: What and Why
  2. OpenTelemetry Traces from the Browser
  3. Real User Monitoring and Web Vitals
  4. Correlating Frontend and Backend Traces
← Back to React Academy