Prompt
How do I trace a user request from frontend to backend services
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
To trace a user request from the frontend through backend services, you want distributed tracing plus consistent request IDs/log correlation.
1) Add a trace ID at the edge
When a request starts in the frontend or first backend entry point, generate or accept a trace ID.
Common standards:
- W3C Trace Context:
traceparent,tracestate - B3:
X-B3-TraceId,X-B3-SpanId, etc. - A simpler internal header like
X-Request-Idcan work, but it’s less powerful than full tracing.
2) Propagate the trace headers everywhere
Every service involved should:
- read the incoming trace headers
- create a new span for its work
- forward the trace headers to downstream services
This lets you see the full request path across:
- browser / frontend
- API gateway / load balancer
- service A
- service B
- database calls
- external APIs
3) Use a tracing system
Send traces to a backend like:
- OpenTelemetry
- Jaeger
- Zipkin
- Datadog
- New Relic
- Grafana Tempo
OpenTelemetry is the most common open standard now.
4) Correlate logs with trace IDs
In every service log, include:
trace_idspan_id- maybe
user_id,request_id,tenant_id
Then you can jump from a slow trace to the exact logs for that request.
Example log line:
{
"level": "info",
"message": "Fetched user profile",
"trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
"span_id": "00f067aa0ba902b7"
}
5) Instrument frontend and backend
Frontend
- Capture page/app actions and outgoing API requests
- Propagate trace headers on fetch/XHR if possible
- Instrument browser interactions with OpenTelemetry JS or a vendor SDK
Backend
- Add middleware/interceptors in your web framework
- Instrument HTTP clients, DB clients, message queues, and caches
6) Use a simple flow
Typical request chain:
- User clicks button in browser
- Frontend creates/uses trace context
- Request sent to API gateway with trace headers
- Gateway forwards headers to Service A
- Service A calls Service B with same trace context
- Service B queries DB
- All spans appear in tracing UI as one trace
7) What to inspect when debugging
Look at:
- total latency
- which span is slow
- downstream dependency timing
- error tags/status codes
- retries/timeouts
- whether headers are missing somewhere
8) Practical recommendation
If you want the easiest modern setup:
- Use OpenTelemetry
- Export to Jaeger or Grafana Tempo
- Add trace IDs to logs
- Instrument frontend + gateway + all backend services
9) Minimal checklist
- Choose a trace standard: W3C Trace Context
- Instrument frontend and backend with OpenTelemetry
- Propagate trace headers across all HTTP calls
- Add trace IDs to logs
- Export traces to a tracing UI
- Verify a single request appears end-to-end
If you want, I can also give you:
- a Node.js / Express example,
- a Python / FastAPI example, or
- a system design diagram for end-to-end tracing.