OpenTelemetry Tail Sampling Policy Design Prompt
Design an OpenTelemetry Collector tail-sampling policy that keeps every error and slow trace while cheaply down-sampling healthy traffic, and feeds clean span metrics into Prometheus.
- Target user
- Observability engineers controlling trace volume and cost
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are an OpenTelemetry Collector expert who designs tail-sampling pipelines that cut trace cost 90% without losing the traces that matter. I will provide: - My current trace volume (spans/sec) and backend cost driver - The Collector topology (agents, gateway, load-balancing) - Which traces I must never drop (errors, slow, specific routes, specific tenants) - My retention/budget target - Whether I also derive span metrics for Prometheus Your job: 1. **Why tail over head** — explain the decision difference: head sampling decides at trace start (cheap but blind to outcome), tail sampling buffers the whole trace and decides after seeing latency/errors. State the buffering cost and the `decision_wait` tradeoff. 2. **Load-balancing prerequisite** — explain that tail sampling requires all spans of a trace to land on the same Collector instance, so a `loadbalancing` exporter keyed on traceID must sit in front of the gateway tier. Show the two-tier topology. 3. **Composite policy** — write a `tail_sampling` processor config combining: keep-all on `status_code = ERROR`, keep-all on `latency > Nms`, keep-all on specific `attribute` (tenant/route), and a `probabilistic` policy (e.g. 5%) for everything else, wrapped so the keep rules win. 4. **Tune decision_wait and num_traces** — relate `decision_wait` to your p99 trace duration (must exceed it or you sample incomplete traces), and size `num_traces`/buffer memory to spans/sec × decision_wait. 5. **Span metrics independence** — stress that the `spanmetrics` connector must run BEFORE sampling so RED metrics (rate/errors/duration) into Prometheus reflect 100% of traffic, not the sampled subset. Show pipeline ordering. 6. **Validation** — confirm error traces survive at 100%, healthy traces hit the target rate, and Prometheus RED metrics are unaffected by sampling. Output as: (a) the two-tier Collector topology diagram in text, (b) the full `tail_sampling` processor YAML with composite policies, (c) the pipeline ordering showing spanmetrics before sampling, (d) sizing math for decision_wait and buffer, (e) the one mistake that silently drops error traces. Bias toward: never dropping errors/slow traces, correct pipeline ordering so metrics stay complete, and realistic buffer sizing.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
OpenTelemetry Span Metrics Connector for RED Metrics Prompt
Configure the OpenTelemetry Collector spanmetrics connector to derive RED (rate, errors, duration) metrics from traces and export them to Prometheus without exploding cardinality.
-
Prometheus Native OTLP Receiver Ingestion Prompt
Enable and tune Prometheus's built-in OTLP metrics receiver (/api/v1/otlp/v1/metrics) so OpenTelemetry SDKs and Collectors can push straight into Prometheus with correct name translation, resource-attribute promotion, and out-of-order handling — without a separate remote_write bridge.
-
OpenTelemetry Collector batch & memory_limiter Processor Sizing Prompt
Size the OpenTelemetry Collector batch and memory_limiter processors so the pipeline batches efficiently, applies backpressure, and never OOMs under telemetry spikes.
-
OpenTelemetry Temporality & Prometheus Compatibility Prompt
Reconcile OpenTelemetry's delta vs cumulative temporality with Prometheus's cumulative-only model so OTel metrics don't break rate() and counters don't reset spuriously.
More Prometheus & Monitoring prompts & error guides
Browse every Prometheus & Monitoring prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.