Prompt
How do I trace requests in Kubernetes microservices
Latest observation
To trace requests in Kubernetes microservices, use distributed tracing: assign each request a trace ID, propagate it across services, and export spans to a tracing backend.
Typical approach
1) Instrument each service
Add tracing to every microservice so it creates spans for:
- incoming HTTP/gRPC requests
- outgoing calls to other services
- important internal operations like DB queries
Common libraries:
- OpenTelemetry (recommended standard)
- language SDKs for Java, Go, Python, Node.js, .NET, etc.
2) Propagate context between services
Make sure the trace context is passed in request headers, for example:
traceparent/tracestate(W3C standard)- or vendor-specific headers if needed
This lets all spans from one request be linked into a single trace.
3) Export spans to a collector
Use an OpenTelemetry Collector running in Kubernetes to receive spans from your apps and forward them to:
- Jaeger
- Zipkin
- Grafana Tempo
- commercial tools like Datadog, New Relic, Honeycomb, Dynatrace, etc.
4) Visualize traces
Use the backend UI to inspect:
- which service was slow
- where latency was introduced
- failures and retries
- the full path of a request across services
Common Kubernetes setup
A very common architecture is:
app pods → OpenTelemetry Collector → tracing backend
You can run the collector as:
- a DaemonSet
- a Deployment
- a sidecar in each pod, though this is less common now
Best practice: use OpenTelemetry
OpenTelemetry gives you:
- consistent instrumentation across languages
- automatic instrumentation for popular frameworks
- standard propagation
- vendor-neutral export
What to trace
At minimum, capture:
- request start/end
- downstream HTTP/gRPC calls
- DB calls
- message queue publish/consume
- errors and exceptions
- retries and timeouts
Add useful attributes:
- service name
- route/path
- HTTP method/status
- user/session IDs only if safe and not sensitive
- pod/node/namespace metadata
Example flow
User sends request to api-gateway:
- Gateway starts a trace
- Gateway calls
orders-servicewith trace headers orders-servicecallsinventory-service- Each service creates a child span
- Collector receives spans
- Jaeger/Tempo shows one end-to-end trace
Helpful tools
OpenTelemetry
- SDKs and auto-instrumentation
- Collector
- tracing/metrics/logs support
Backends
- Jaeger
- Grafana Tempo
- Zipkin
Kubernetes integrations
- Helm charts for collector/backend
- service annotations for metadata
- ingress/controller instrumentation if needed
Minimal implementation steps
- Install an observability backend
- Deploy OpenTelemetry Collector in Kubernetes
- Add OpenTelemetry SDK or auto-instrumentation to each service
- Configure export to collector
- Ensure trace headers are propagated between services
- Open the tracing UI and search by service, latency, or error
Example headers
If using W3C trace context, you’ll see headers like:
traceparent: 00-<trace-id>-<span-id>-01tracestate: ...
Common pitfalls
- missing context propagation between services
- sampling set too low, causing traces to disappear
- high-cardinality labels causing performance issues
- forgetting to instrument async jobs or queue consumers
- tracing sensitive data accidentally
If you want, I can give you:
- a Kubernetes + OpenTelemetry Helm setup, or
- code examples for tracing in Java/Go/Python/Node.js.