How do you handle distributed tracing and observability in microservices?
Learn how to handle observability in microservices with logs, metrics and distributed tracing using OpenTelemetry and Jaeger — with examples and interview tips.
Expected Interview Answer
You handle observability in microservices by combining the three pillars — logs, metrics, and distributed traces — and using distributed tracing to follow a single request as it propagates a shared trace context (trace ID and span IDs) across every service it touches.
Each service instruments its code (typically with OpenTelemetry) to create spans and propagate the trace context through HTTP or messaging headers. Spans are exported to a backend like Jaeger, Zipkin, or Tempo, which stitches them into an end-to-end timeline showing where latency and errors occur. Structured logs carry the trace ID for correlation, and metrics feed dashboards and alerts, giving you a complete picture across service boundaries.
- Pinpoints latency bottlenecks across service hops
- Correlates logs, metrics and traces by trace ID
- Reveals failure root cause in complex call graphs
- Vendor-neutral instrumentation via OpenTelemetry
- Faster mean-time-to-resolution during incidents
AI Mentor Explanation
A distributed trace is like tracking a single ball from the bowler's run-up through the batter's shot, the fielder's throw and the wicket-keeper's collection — each touch is a timed span. The scorecard and match commentary are your logs and metrics. Together they let you replay exactly where a run was lost, just as tracing shows where a request slowed across services.
Step-by-Step Explanation
Step 1
Instrument services
Add OpenTelemetry SDKs so each service creates spans for incoming and outgoing calls.
Step 2
Propagate context
Pass the trace ID and span context through HTTP or messaging headers on every hop.
Step 3
Export spans
Send spans to a collector and backend such as Jaeger, Zipkin or Tempo.
Step 4
Correlate signals
Include the trace ID in structured logs and tie metrics to the same request identifiers.
Step 5
Visualize and alert
Use dashboards and alerts on latency, error rate and traces to detect and diagnose issues.
What Interviewer Expects
- Knowledge of the three pillars: logs, metrics, traces
- Understanding of trace context propagation
- Familiarity with OpenTelemetry and a tracing backend
- How trace IDs correlate logs and metrics
- Awareness of sampling to control overhead
Common Mistakes
- Treating logging alone as full observability
- Failing to propagate the trace context across services
- Ignoring sampling and overwhelming the backend
- Not correlating logs and metrics with trace IDs
Best Answer (HR Friendly)
“In microservices a single request touches many services, so we tag it with a trace ID and follow it end to end, while also collecting logs and metrics. This lets us quickly see where a request slowed down or failed across the whole system.”
Code Example
const { NodeSDK } = require('@opentelemetry/sdk-node')
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node')
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http')
const sdk = new NodeSDK({
traceExporter: new OTLPTraceExporter({ url: 'http://collector:4318/v1/traces' }),
instrumentations: [getNodeAutoInstrumentations()],
})
sdk.start()Follow-up Questions
- What are the three pillars of observability?
- How does trace context propagation work across HTTP calls?
- Why is sampling important in distributed tracing?
- How does OpenTelemetry differ from Jaeger and Zipkin?
- How do you correlate a log line with a specific trace?
MCQ Practice
1. What uniquely ties together all spans of a single request?
A shared trace ID (with per-hop span IDs) links every span of one request across services.
2. Which is a vendor-neutral standard for instrumentation?
OpenTelemetry provides vendor-neutral APIs and SDKs for traces, metrics and logs.
3. Which are the three pillars of observability?
Observability is built on logs, metrics and distributed traces working together.
Flash Cards
Three pillars of observability — Logs, metrics, and distributed traces — used together for full visibility.
Trace vs span — A trace is the whole request journey; a span is one timed operation within it.
Context propagation — Passing the trace ID and span context through headers so hops join one trace.
Why sampling? — It limits trace volume and overhead while keeping representative data.
Continue Learning
Related Interview Questions
What is the difference between centralized and distributed logging in microservices?
medium
What is metric cardinality, and how do you keep microservice observability affordable without losing the ability to debug?
medium
A customer reports a failed order. How do you reconstruct what happened across eight services' logs?
medium
What is Distributed Tracing and Why Is It Needed?
medium