How Distributed Tracing Works
Distributed tracing connects spans across service boundaries by propagating trace context through HTTP headers:- Service A starts a trace and adds trace headers to outgoing requests
- Service B continues the trace by reading the headers and creating child spans
- Service C continues the same trace, creating a complete picture
Automatic Instrumentation
Sentry automatically propagates trace context for common HTTP clients:Trace headers (
sentry-trace and baggage) are automatically added to outgoing requests for services in your tracePropagationTargets.Trace Propagation Targets
Control which requests include trace headers:Default Behavior
By default, trace context is propagated to:localhost(all ports)- Same-origin requests
Continuing Traces
Server-Side
Continue a trace from incoming request headers:Client-Side
Continue a trace from meta tags (for server-side rendered apps):Trace Headers
sentry-trace Header
Format:{trace_id}-{span_id}-{sampled}
- trace_id: 32-character hex string
- span_id: 16-character hex string
- sampled:
1(sampled) or0(not sampled)
baggage Header
Carries additional metadata:Manual Propagation
Manually add trace headers to requests:Cross-Service Example
Service A (Frontend)
Service B (Backend API)
Service C (Payment Service)
- User click (Frontend)
- API request (Frontend → Backend)
- Save order (Backend)
- Payment request (Backend → Payment Service)
- Charge card (Payment Service)
- Record transaction (Payment Service)
Dynamic Sampling Context
Dynamic Sampling Context (DSC) carries metadata for sampling decisions:Sampling Considerations
Head-Based Sampling
Sampling decision is made at the start of the trace:Per-Service Sampling
Each service can make its own sampling decisions:For consistent distributed traces, use head-based sampling (single decision at the root) rather than per-service sampling.
Debugging Distributed Traces
Check Trace Headers
Verify Trace Continuity
Best Practices
- Configure trace propagation targets: Only propagate to services you control
- Use consistent DSNs: Ensure all services send data to the same Sentry project (or linked projects)
- Honor parent sampling: Don’t override the sampling decision from the root
- Set meaningful operation names: Use standard operation types (
http.server,http.client, etc.) - Add service identifiers: Tag spans with service names for easy filtering
- Monitor trace completion: Ensure all services successfully propagate trace context
Common Pitfalls
Missing Trace Headers
Incorrect Trace Continuation
Next Steps
Tracing
Learn about traces and spans
Spans
Work with individual spans
Performance
Performance monitoring overview
Session Replay
Combine traces with session replay