Control trace volume in high-throughput scenarios with smart sampling strategies
By default, Atla Insights instruments and logs all traces. In high-throughput scenarios, you may want to sample traces rather than logging every execution to manage trace limits while maintaining observability.
Implement your own sampling logic using OpenTelemetry samplers.Here is an example:
Copy
Ask AI
from atla_insights import configurefrom opentelemetry.sdk.trace.sampling import Sampler, SamplingResult, Decisionfrom opentelemetry.trace import Linkfrom opentelemetry.util.types import Attributesfrom typing import Optional, Sequenceclass CustomSampler(Sampler): def __init__(self, base_ratio: float = 0.2): self.base_ratio = base_ratio def should_sample( self, parent_context, trace_id: int, name: str, kind, attributes: Optional[Attributes] = None, links: Optional[Sequence[Link]] = None, trace_state=None, ) -> SamplingResult: # Sample all error traces if attributes and attributes.get("error", False): return SamplingResult(Decision.RECORD_AND_SAMPLE) # Sample all user-facing interactions if attributes and attributes.get("user_facing", False): return SamplingResult(Decision.RECORD_AND_SAMPLE) # For other traces, use base sampling ratio if (trace_id % 100) < (self.base_ratio * 100): return SamplingResult(Decision.RECORD_AND_SAMPLE) return SamplingResult(Decision.NOT_RECORD)my_sampler = CustomSampler(base_ratio=0.05) configure( token="<MY_ATLA_INSIGHTS_TOKEN>", sampling=my_sampler, )
Atla Insights is compatible with OpenTelemetry samplers. Learn more about OpenTelemetry samplers.
The Atla Insights platform is not intended to work well with partial traces. We highly recommend using either ParentBased or StaticSampler samplers to ensure consistent trace handling.