Distributed Tracing in New Relic: Following a Request Across Services
In a monolith, a slow request is in one place. In microservices, one click can pass through an API gateway, auth service, product service, pricing service, a database, and a third-party API. Distributed tracing shows the full journey.
Core Concepts
- Trace — the entire journey of one request
- Span — one operation within it (an HTTP call, a DB query, a function)
- Parent/child — spans nest to show what called what
- Trace context — IDs passed between services in headers (W3C
traceparent)
How It Works
Each service's agent (or OpenTelemetry SDK) reads the incoming trace headers, creates its own spans, and passes the context to downstream calls. New Relic stitches the spans together into a waterfall view.
Modern New Relic agents enable distributed tracing by default. Make sure every service in the chain is instrumented — one missing service breaks the picture.
Reading a Trace Waterfall
Look for:
- The longest bar — where time is actually spent
- Sequential calls that could be parallel — five 100 ms calls in a row
- N+1 queries — the same DB query repeated dozens of times
- Errors — red spans and their messages
- Gaps — time not covered by spans, often uninstrumented code or queuing
Sampling
High-traffic systems generate millions of traces. Options:
- Head-based sampling — decide at the start; cheap, may miss rare errors
- Infinite Tracing (tail-based) — New Relic observes all spans and keeps the interesting ones: slow, errored, or unusual
Useful Queries
SELECT count(*) FROM Span WHERE error IS true
FACET service.name, name SINCE 1 hour ago
SELECT average(duration.ms) FROM Span
WHERE trace.id IN (
SELECT trace.id FROM Span WHERE name = 'POST /checkout' AND duration.ms > 2000 LIMIT MAX
) FACET service.name
Tips
- Add custom attributes (customer tier, region, feature flag) to spans
- Propagate context through message queues (Kafka, SQS) too
- Use the service map to see dependencies discovered from traces
Tracing replaces guesswork with a timeline. In distributed systems, that's the difference between minutes and hours of debugging.