Tracing every request costs too much. How do you design sampling?
IntermediateScenarioTracing and OpenTelemetry
Answer
Situation read → 100% tracing at high volume is expensive; random 1% misses the interesting traces.
What I'd do →
- Head sampling in SDKs:
OTEL_TRACES_SAMPLER=parentbased_traceidratio,OTEL_TRACES_SAMPLER_ARG=0.1as a base. - Tail sampling in the Collector gateway to keep all errors, slow requests and important routes:
processors:
tail_sampling:
decision_wait: 10s
policies:
- {name: errors, type: status_code, status_code: {status_codes: [ERROR]}}
- {name: slow, type: latency, latency: {threshold_ms: 1000}}
- {name: baseline, type: probabilistic, probabilistic: {sampling_percentage: 5}}
- Keep RED metrics from 100% of spans (spanmetrics connector) so rates stay accurate.
Why → You keep the traces worth reading and still get accurate aggregate metrics.
Interview tip → Explain that tail sampling needs all spans of a trace on the same collector (load-balancing exporter by trace ID).
More on Tracing and OpenTelemetry
Your company has 30 microservices and no tracing. How do you roll out distributed tracing?IntermediateTraces stop at service B: you see spans from A, but B's spans start new traces. What is wrong?BeginnerYou set up tail sampling with 4 Collector replicas, but traces are fragmented and error traces are missing. Why?AdvancedA checkout request takes 4 seconds. Walk through how you use a trace to find the cause.BeginnerYour OpenTelemetry Collector is getting OOMKilled under load. How do you stabilise it?IntermediateHow do you trace a request that goes through Kafka from a producer to three consumers?Intermediate