Prompt
I'm building a service mesh environment and need tracing across requests, how do I approach it?
Latest observation
To get tracing working well in a service mesh, think in terms of three layers: instrumentation, context propagation, and collection/export. The mesh helps with propagation and transport, but your apps still need to cooperate.
1) Pick a tracing standard
Use OpenTelemetry if you can. It’s the current standard for traces, metrics, and logs.
- Trace = a request’s journey across services
- Span = one operation within that journey
- Trace context = the IDs that let downstream services link spans together
Recommended context format:
- W3C Trace Context (
traceparent,tracestate) - Optionally baggage for small contextual metadata
2) Instrument the application services
A mesh alone usually can’t produce full application-level traces. You want each service to:
- read incoming trace context
- create child spans for important operations
- inject context into outgoing requests
This is typically done via:
- OpenTelemetry SDKs in your code
- or auto-instrumentation agents for supported runtimes
Minimum goal:
- inbound HTTP/gRPC server span
- outbound client span
- any important internal spans around DB/cache/external calls
3) Make the mesh propagate trace headers
Your sidecars/proxies should forward trace headers consistently.
Depending on the mesh:
- Istio/Envoy: can generate/propagate tracing headers and report spans
- Linkerd: primarily focuses on metrics/identity; tracing support is more limited and often relies on app instrumentation and an external tracing setup
Things to confirm:
- incoming headers are preserved
- outgoing requests include the trace context
- retries/timeouts don’t break trace correlation
- HTTP and gRPC propagation both work
4) Use a collector in the middle
Don’t send traces straight from every service to the backend if you can avoid it. Use an OpenTelemetry Collector:
Common pipeline:
- apps and/or proxies export to OTel Collector
- collector batches, samples, enriches, and forwards
- backend stores and visualizes traces
Collector benefits:
- central config for export
- retries and buffering
- tail-based sampling
- easier backend swaps
5) Choose a tracing backend
Popular options:
- Jaeger
- Tempo
- Zipkin
- Vendor platforms like Datadog, New Relic, Honeycomb, etc.
If you’re already using Prometheus/Grafana, Grafana Tempo is a common fit.
6) Decide where spans come from
You have two main sources of spans:
A. App spans
Best for business context and detailed operations. Examples:
CheckoutService.PlaceOrderPaymentService.AuthorizeCardDB query
B. Mesh/proxy spans
Best for network-level visibility. Examples:
- request routing
- service-to-service latency
- retries, mTLS, failures
Best practice is to use both, but avoid double-counting or confusing span naming.
7) Standardize propagation and sampling
Propagation
Use the same trace context everywhere:
- HTTP:
traceparent - gRPC: metadata propagation
- message queues: carry trace context in message headers
Sampling
Tracing can be expensive, so choose a strategy:
- Head-based sampling: decide at trace start
- Tail-based sampling: decide after seeing the whole trace
For service meshes, tail-based sampling via the collector is often very useful because you can keep:
- all errors
- slow requests
- a percentage of normal traffic
8) Handle async and messaging carefully
Tracing across queues, streams, and async jobs needs explicit propagation.
When producing a message:
- inject trace context into message headers
When consuming:
- extract context and create a child span
This is crucial for:
- Kafka
- RabbitMQ
- SQS/SNS
- Pub/Sub
- background jobs
9) Correlate traces with logs and metrics
For practical debugging, add:
- trace ID into logs
- service, pod, namespace labels into metrics
- exemplars if supported
That way you can jump from:
- alert → metric spike
- metric spike → trace
- trace → specific log lines
10) Validate with a rollout plan
A good rollout approach:
- Set up the collector and backend
- Enable tracing in one or two services
- Confirm context propagation across hops
- Enable mesh proxy tracing if needed
- Add sampling rules
- Roll out service by service
- Add dashboards and alerts around latency/error traces
Common pitfalls
- relying on the mesh alone for full app tracing
- not propagating context across async boundaries
- inconsistent header formats
- too much sampling suppression
- too much span cardinality in names/attributes
- enabling tracing without log correlation
Practical recommendation
If you’re starting fresh:
- use OpenTelemetry
- deploy an OpenTelemetry Collector
- use W3C Trace Context
- instrument apps and enable mesh proxy tracing where supported
- choose tail-based sampling for production if possible
- send traces to Tempo or Jaeger
If you want, I can also give you:
- a reference architecture for Istio/Envoy or Linkerd,
- a step-by-step Kubernetes setup, or
- an example OpenTelemetry configuration for HTTP/gRPC services.