advanced30 min studyLesson 395 in Engineering

Sampling for investigation and sampling for estimation differ

Compare head, tail, and adaptive decisions while preserving inclusion probabilities and refusing biased trace counts as population error rates.

On this page

What you’ll understand

  • Explain what information head and tail samplers can use and what buffering they require.
  • Detect selection bias when outcomes change trace-retention probability.
  • Derive inverse-probability total estimation and state its inclusion-probability assumptions.

Sampling reduces telemetry volume by choosing which observations survive. A uniform random sample can support some population estimates, while deliberately retaining failures or slow traces can be much better for investigation. These are compatible goals only when their selection mechanisms remain explicit. Treating a failure-enriched trace store as an unbiased error counter can produce a compelling but incorrect reliability report. We will distinguish discovery value from statistical representativeness.

Choose when a decision can use an outcome

A head decision happens before the full operation outcome is available, often at span or root-trace creation. A coordinated parent-based policy can help retain a coherent related set, while incompatible decisions or later loss can still create gaps. Tail sampling waits for enough completed observations to apply policies such as keeping errors or long durations. That requires routing related data together, buffering, decision timeouts, and handling late spans. A tail sampler cannot recover spans that an upstream head sampler never recorded or exported.

Adaptive sampling changes rates to meet a volume or investigation budget. Record which policy and effective inclusion probability applied to each estimable observation; a rate configured at noon need not describe a span retained earlier or after several collection stages. Dependent and consistent sampling stages do not always combine by naively multiplying nominal configuration percentages. Follow the actual probability contract. Deterministic exclusions with zero inclusion probability make some population totals unidentifiable from the sample alone, regardless of how sophisticated a later query appears.

T^=∑i∈UIiyiπi,E[T^]=∑i∈Uyi\widehat{T}=\sum_{i\in U}\frac{I_i y_i}{\pi_i},\qquad \mathbb{E}[\widehat{T}]=\sum_{i\in U}y_i
For a fixed finite population U, y_i is the quantity of interest, I_i indicates inclusion, and known positive pi_i=E[I_i] is the actual inclusion probability. Linearity gives unbiased total estimation without requiring independent selections. Unknown probabilities, zero-probability exclusions, or unmodeled loss break this claim.↔ Scroll wide equations horizontally.

Outcome enrichment changes observed fractions

If failures are retained more often than successes, the raw fraction of failures among stored traces overstates their population fraction. This can be desirable for debugging but must be labeled accordingly. An inverse-probability estimator can estimate totals when inclusion probabilities are known, positive, and preserved through the relevant pipeline. A ratio of two estimated totals is not generally exactly unbiased in a finite sample. If a reliable unsampled request total is independently available, dividing an unbiased estimated failure total by that known denominator has a clearer expectation argument.

Sampling uncertainty remains even with a valid estimator. Rare events can be missed, weights can create high variance, and trace-level selection correlates spans within one trace. Confidence calculations must use the actual sampling unit and design rather than treating every retained span as an independent request. Compare derived estimates with dedicated complete counters where possible, and expose policy changes or probability metadata gaps. A selected set of interesting traces is valuable evidence about possible failures, but cannot establish how frequently all users experienced them without the missing statistical conditions.

P(E∣K)=P(K∣E)P(E)P(K∣E)P(E)+P(K∣¬E)P(¬E)P(E\mid K)=\frac{P(K\mid E)P(E)}{P(K\mid E)P(E)+P(K\mid\neg E)P(\neg E)}
E denotes an error and K retention, with a positive denominator. Different retention probabilities for errors and non-errors change the raw retained error fraction. This conditional-probability identity is dimensionless and does not by itself supply unknown production inclusion probabilities.↔ Scroll wide equations horizontally.

Test both budget control and inference metadata

Exercise the policy with normal requests, rare failures, long-running traces, bursts, missing children, and late arrivals. Measure incoming and retained volume, buffering, dropped data, and the probability information available to queries. Verify that an upstream sampling flag or trace ID is not accepted as proof of randomness without the documented generation assumptions. OpenTelemetry's probability-sampling specification provides explicit mechanisms and qualifications; its development status and deployed SDK support still need checking. Do not promise an estimator merely because a UI shows a sampling percentage.

For an independent fixed-probability example, Reset the sampling lab, set both p=0.2 and n=25, predict retention-fraction mean 0.2 and variance 0.0064, then Play or Step. Reset and set both p=0.2 and n=100 to predict variance 0.0016. The exact binomial masses describe hypothetical independent decisions, not actual random draws; playback highlights outcomes. Its normal overlay is approximate, and the displayed Berry–Esseen bound concerns standardized CDF error, not per-bar error. The instrument does not model tail policies, correlated traces, adaptive rates, or inverse weights.

A useful diagnostic sample can look alarmingly biased

A fixed population has 10,000 requests: 100 errors and 9,900 successes. A hypothetical policy keeps every error and independently keeps each success with probability 0.01. One realized sample contains all 100 errors and 99 successes, with no other loss.

  1. The raw retained error fraction is 100/(100 + 99), approximately 50.25 percent. The population error fraction was only 100/10,000 = one percent.

  2. With the stated true inclusion probabilities, estimated error total is 100/1 = 100 and estimated success total is 99/0.01 = 9,900. This realized sample's weighted totals match the population counts.

  3. The estimated totals have the appropriate expectation under this design, but a ratio of estimated totals is not generally exactly unbiased across finite samples. Here a separately known denominator of 10,000 yields error fraction 100/10,000 = one percent.

The result

The failure-enriched sample is excellent for finding errors while its unweighted 50.25 percent fraction is unsuitable as the service's population error rate.

Explore the model

Interactive lab

Interactive lab · sampling

Retention uncertainty under a fixed independent policy

Reset, set both p=0.2 and n=25, predict fraction variance 0.0064, then Play or Step. Reset and re-enter p=0.2 and n=100 for variance 0.0016. Exact binomial masses are not random draws; the normal overlay is approximate and its Berry–Esseen bound is for standardized CDFs, not bars. No tail/adaptive policy or inverse weighting is modeled.

Retention uncertainty under a fixed independent policyExact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Current readings: Mean sample proportion: 0.5; Sample-mean variance: 0.0125; Uniform CDF error bound: ≤ 0.1062. All parameters are adjustable with the labeled controls below.Exact distribution of the mean of 20 independent Bernoulli variables with success probability 0.5; playback highlights outcome 0.00.250.50.75100.0580.1150.1730.23Sample mean · k / nProbability massNormal bin masses are an approximationk = 0 · exact probability = 9.54e-7
Exact binomial massNormal interval massHighlighted outcome / mean
Mean sample proportion
0.5
Sample-mean variance
0.0125
Uniform CDF error bound
≤ 0.1062
t = 0 s

Exact binomial masses for the mean of n independent Bernoulli trials, compared with normal mass between adjacent half-count boundaries; normal tails outside the finite support remain outside the bars. Playback highlights outcomes, not random samples. The Berry–Esseen bound applies to standardized CDFs, not individual bars or continuity-corrected errors. At p = 0 or 1, normal comparison and that bound are disabled. Normal-CDF evaluation uses a numerical approximation with absolute error below 7.5×10⁻⁸ (at most 1.5×10⁻⁷ per interval, before rounding). Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA valid fixed-probability model quantifies one uncertainty; outcome-based selection and pipeline loss need additional assumptions and metadata.

Check your understanding

A trace store deliberately retains all errors but only a small fraction of successes. What is required before using it to estimate a population error rate?

Try it yourself

A realized sample contains twenty failures retained with probability one and eighty successes retained with actual probability 0.1. Compute unweighted error fraction and inverse-probability total estimates, and qualify the weighted ratio.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Divide each retained category count by its own inclusion probability before comparing totals.

Compare with the solution

The unweighted fraction is 20/100 = twenty percent. Estimated failures are twenty and estimated successes are 80/0.1 = 800, giving estimated total 820 and ratio 20/820 ≈2.44 percent. Under known positive inclusion probabilities and no unmodeled loss, the totals have an unbiased expectation; their finite-sample ratio is not generally exactly unbiased and still has sampling uncertainty.

Take it with you

  • Head and tail decisions have different available information, buffering needs, and upstream limits.
  • Failure-enriched traces support investigation without making raw stored fractions representative.
  • Population estimation needs actual inclusion probabilities, valid denominators, loss accounting, and design-aware uncertainty.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.