Implementing Sentry Distributed Tracing Across Microservices
Configure Sentry distributed tracing to link microservice requests via header propagation, with Node.js and Python configuration examples and limits for sample rates.
08 Aug 2025, 11:39 UTC

The Problem: Tracing Requests Across Service Boundaries
In a microservices architecture, a single user request often triggers calls across multiple services. Standard logs only capture the final service's output, leaving the originating service blind to where latency or failures originate.
The useful takeaway: Distributed tracing links these events into a single trace using a shared Trace ID propagated via HTTP headers.
Trace Propagation Mechanism
Sentry injects two headers on outbound requests: sentry-trace carries the Trace ID and Span ID, while baggage carries persistent key-value metadata. Downstream services extract these headers and adopt the existing Trace ID, creating parent-child span relationships.
const Sentry = require('@sentry/node'); Sentry.init({ dsn: 'https://[contact removed]/123', tracesSampleRate: 0.1 }); async function callBackend() { await axios.get('http://backend-service/api/data'); }Service B (Python downstream)
import sentry_sdk from sentry_sdk.integrations.flask import FlaskIntegration from flask import Flask sentry_sdk.init({ dsn: 'https://[contact removed]/123', integrations: [FlaskIntegration()], traces_sample_rate: 0.1 }) app = Flask(__name__) @app.route('/api/data') def get_data(): return {'status': 'ok'}Critical Limits and Common Mistakes
Header Stripping by Infrastructure
Load balancers, API gateways, or reverse proxies may strip unknown HTTP headers. If sentry-trace is removed before reaching the downstream service, the trace breaks and a new unrelated trace begins.
Sample Rate Overhead
Setting tracesSampleRate to 1.0 in high-traffic environments can exhaust monthly quotas and add measurable latency. Start with a low rate (e.g., 0.1) and increase only during debugging.
Clock Skew
Physical server clock differences can cause spans to appear slightly out of order in the Sentry UI, though this rarely impacts functional diagnosis.
Verifying the Implementation
- Inspect the wire: use
curl -vor a proxy to confirm the outgoing request from Service A to Service B contains thesentry-traceheader. - Check the Performance dashboard: in the Sentry UI, navigate to Performance, select a transaction from Service A, and verify a downstream span for Service B appears.
- Match Trace IDs: compare the trace_id recorded in Service A logs with the trace_id in Service B logs for the same request.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.