Tracing Sampling
Tracing sampling is a crucial technique for managing the volume of trace data in production environments. By default, Traceloop traces every request, which works well for debugging or development but can become expensive and noisy in high-traffic production systems.
Sampling helps in several ways: it reduces noise in traces, helping you focus on important traces while maintaining visibility into your system. It also helps with cost management in terms of storage, processing, and network bandwidth, making it essential for production deployments.
Sampling Strategies
OpenTelemetry supports several built-in samplers, but in practice, two cover most use cases:
1. TraceIdRatioBased Sampler
Samples a fixed percentage of root traces. This sampler makes sampling decisions independently for each trace.
Pros: Simple to configure, predictable sampling rate, deterministic behavior
Cons: May create partial traces if child spans are sampled differently, especially when spans are spread across multiple microservices or services with different sampling configurations.
2. ParentBased Sampler (Recommended)
Samples a fixed percentage of root traces and ensures that child spans follow the parent’s sampling decision, maintaining complete trace integrity.
Pros: Maintains trace integrity, prevents partial traces, ensures complete trace visibility when sampled
Cons: Slightly more complex configuration, but worth the additional setup for production environments
Troubleshooting
Partial Traces
If you see partial traces (missing spans in the middle of a trace), ensure you’re using ParentBased
sampler:
Too Much Data
If you’re still collecting too much data or experiencing high costs, reduce the sampling rate:
Too Little Data
If you need more visibility for debugging or monitoring, increase the sampling rate: