Sampling in distributed tracing controls the amount of data collected from your application. It helps you balance between having enough details to debug problems and avoiding high storage or processing costs. With sampling, you can decide which traces to keep and which to discard, making your observability setup efficient and cost-effective.
Sampling determines how much data OpenTelemetry collects. Instead of recording every trace, sampling allows you to collect a fraction of them, focusing on what matters most.
Without sampling, collecting traces for every request can generate enormous amounts of data, leading to high costs and slower systems. Sampling solves this by:
OpenTelemetry allows you to configure sampling strategies that match your app's needs. Here’s an example of head-based sampling in TypeScript:
1import { ParentBasedSampler, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base';
2import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
3
4// Set up a 10% sampling rate
5const sampler = new ParentBasedSampler({
6 root: new TraceIdRatioBasedSampler(0.1), // Sample 10% of traces
7});
8
9const provider = new NodeTracerProvider({
10 sampler,
11});
12provider.register();
This configuration ensures only 10% of traces are recorded, reducing data usage while still collecting enough for analysis.
Sampling is useful when:
Otelic.com provides the market's best price per GB, allowing you to store more traces and logs without breaking your budget. With its cost-effective pricing model, you can manage sampled traces efficiently while still keeping enough data for in-depth debugging. Combined with ClickHouse-powered search, Otelic helps you quickly find high-value traces, link them to related logs, and identify root causes—all while optimizing storage costs. This balance ensures you get the insights you need without overspending on observability.