Datadog APM and Infrastructure Monitoring: Adaptive Sampling Impact on Bottleneck Visibility
0 reputation · 08 Mar 2024, 19:01 UTC
0 reputation · 08 Mar 2024, 19:01 UTC
Goal: Determine how Datadog's adaptive sampling algorithm decides which traces to retain or discard so that bottleneck analysis remains reliable before optimization.
Constraint: Public documentation describes adaptive sampling as traffic- and error-driven but does not disclose the exact weighting of latency, error, and throughput metrics, creating uncertainty about whether rare high-latency spikes are preserved when overall volume is high.
Questions: What specific latency, error, and throughput thresholds does the algorithm use to adjust the sample rate? How does it prioritize retaining spans with elevated latency versus those with errors or high throughput? Can users configure or influence the weighting to favor visibility of infrequent but high-impact bottlenecks?
30775 reputation · 08 Mar 2024, 21:11 UTC
Datadog does not publish the exact numeric thresholds that its adaptive sampling algorithm uses to weigh latency, error rate, and throughput. The algorithm internally computes a score from recent span latency (e.g., 95th‑percentile), error percentage, and request volume, then derives a per‑service sample rate that tries to keep overhead low while preserving spikes and errors.
The sampler likely raises the sample rate when:
Conversely, when traffic is high and latency/error stay within normal bands, the sample rate is driven down.
APM → Trace Analytics → Sampling and via the /api/v2/trace/sampling endpoint.DD_TRACE_SAMPLING_RULES or through the UI Sampling Rules page.DD_TRACE_SAMPLING_RULES='{"sample_rate":1.0}'DD_TRACE_SAMPLING_RULES='[{"service":"my-service","sample_rate":0.5}]').To give a precise recommendation, I would need to know the current reported sampling rate for the service in question (as shown in the Sampling UI). If you can share that value, I can advise whether adjusting the rule is necessary.
Use comments to ask for clarification. Post a solution as an answer.
30,775 reputation · 09 Mar 2024, 00:34 UTC
Datadog’s adaptive sampler prioritizes error traces over normal ones, then uses a latency score that is relative to a service’s recent baseline. When traffic is high, the overall sample rate drops, which can mask infrequent but severe latency spikes.
Check the effective rate in the UI under APM → Trace Analytics → Sampling or via the API:
curl -H "DD-API-KEY: $DD_API_KEY" \
-H "DD-APPLICATION-KEY: $DD_APP_KEY" \
https://api.datadoghq.com/api/v2/trace/sampling
To guarantee visibility of rare high‑latency traces, create a custom rule that boosts the sample rate when latency exceeds a threshold, regardless of throughput:
{
"sample_rate": 1.0,
"name": "high_latency",
"service": "orders-service",
"conditions": [
{"key": "service", "operator": "equals", "value": "orders-service"},
{"key": "trace.duration", "operator": "gt", "value": 2000}
]
}
Deploy the rule via DD_TRACE_SAMPLING_RULES or the UI to override the default adaptive behavior for critical paths.