Skip to content

Commit 3055661

Browse files
committed
[trace/sampling] Revises ProbabilitySampler spec to avoid and/or erase ot.th key if trace ID randomness and an explicit rv value is not available.
1 parent 50149c2 commit 3055661

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

specification/trace/sdk.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -506,32 +506,32 @@ to use ProbabilitySampler.
506506
**Status**: [Development](../document-status.md)
507507

508508
The `ProbabilitySampler` implements simple, ratio-based probability sampling using randomness features specified in the [W3C Trace Context Level 2][W3CCONTEXTMAIN] Candidate Recommendation.
509-
OpenTelemetry follows W3C Trace Context Level 2, which specifies 56 bits of randomness,
510-
[specifying how to make consistent probability sampling decisions using 56 bits of randomness][CONSISTENTSAMPLING].
509+
W3C Trace Context Level 2 specifies 56 bits of randomness.
510+
OpenTelemetry follows that model and [specifies how to make consistent probability sampling decisions using the 56 bits of randomness][CONSISTENTSAMPLING].
511511

512-
The `ProbabilitySampler` sampler MUST ignore the parent `SampledFlag`.
512+
The `ProbabilitySampler` MUST ignore the parent `SampledFlag`.
513513
For respecting the parent `SampledFlag`, see the `ParentBased` sampler specified below.
514514

515515
Note that this is a non-composable form of probability
516-
sampler. `ProbabilitySampler` directly implements the SDKs Sampler
516+
sampler. `ProbabilitySampler` directly implements the SDK's Sampler
517517
API, whereas [`ComposableProbability`](#composableprobability) is the
518518
composable form for use with [`CompositeSampler`](#compositesampler).
519519

520520
[W3CCONTEXTMAIN]: https://www.w3.org/TR/trace-context-2/
521521

522-
##### `ProbabilitySampler` sampler configuration
522+
##### `ProbabilitySampler` configuration
523523

524-
The `ProbabilitySampler` sampler is typically configured using a 32-bit or 64-bit floating point number to express the sampling ratio.
524+
The `ProbabilitySampler` is typically configured using a 32-bit or 64-bit floating point number to express the sampling ratio.
525525
The minimum valid sampling ratio is `2^-56`, and the maximum valid sampling ratio is 1.0.
526-
From an input sampling ratio, a rejection threshold value is calculated; see [consistent-probability sampler requirements][CONSISTENTSAMPLING] for details on converting sampling ratios into thresholds with variable precision.
526+
From the input sampling ratio, a rejection threshold value is calculated; see [consistent-probability sampler requirements][CONSISTENTSAMPLING] for details on converting sampling ratios into thresholds with variable precision.
527527

528528
[CONSISTENTSAMPLING]: ./tracestate-probability-sampling.md
529529

530-
##### `ProbabilitySampler` sampler algorithm
530+
##### `ProbabilitySampler` sampling algorithm
531531

532-
Given a Sampler configured with a sampling threshold `T` and Context with randomness value `R` (typically, the 7 rightmost bytes of the trace ID), when `ShouldSample()` is called, it uses the expression `R >= T` to decide whether to return `RECORD_AND_SAMPLE` or `DROP`.
532+
Given a `ProbabilitySampler` configured with a sampling threshold `T` and Context with randomness value `R` (typically, the 7 rightmost bytes of the trace ID), when `ShouldSample()` is called, it uses the expression `R >= T` to decide whether to return `RECORD_AND_SAMPLE` or `DROP`.
533533

534-
* If randomness value (R) is greater or equal to the rejection threshold (T), meaning when (R >= T), return `RECORD_AND_SAMPLE`, otherwise, return `DROP`.
534+
* If randomness value (R) is greater than or equal to the rejection threshold (T), meaning when (R >= T), return `RECORD_AND_SAMPLE`, otherwise, return `DROP`.
535535
* When (R >= T), the OpenTelemetry TraceState SHOULD be modified to include the key-value `th:T` for rejection threshold value (T), as specified for the [OpenTelemetry TraceState `th` sub-key][TRACESTATEHANDLING].
536536

537537
[TRACESTATEHANDLING]: ./tracestate-handling.md#sampling-threshold-value-th
@@ -542,21 +542,22 @@ When a `ProbabilitySampler` makes a decision for a non-root Span
542542
based on TraceID randomness, there is a possibility that the TraceID
543543
was in fact generated by an older SDK, unaware of this specification.
544544
The Trace random flag lets us disambiguate these two cases. This flag
545-
propagates information to let ProbabilitySampler Samplers confirm that
546-
TraceIDs are random, however this requires W3C Trace Context Level 2
547-
to be supported by every Trace SDK that has handled the context.
548-
549-
When a ProbabilitySampler Sampler makes a decision for a non-root Span
545+
propagates information to let ProbabilitySampler confirm whether
546+
TraceIDs are random. For this disambiguation to work across the trace,
547+
each Trace SDK that has handled the context MUST propagate the trace
548+
flags from `traceparent` without dropping bits it does not interpret, so
549+
the Random flag can reach downstream samplers. An SDK does not need to
550+
implement all of W3C Trace Context Level 2 for this to work; forwarding
551+
the trace flags unchanged is sufficient.
552+
553+
When a ProbabilitySampler makes a decision for a non-root Span
550554
using [TraceID randomness when the Trace random flag was not
551-
set](#presumption-of-traceid-randomness), the SDK SHOULD issue a
552-
warning statement in its log with a compatibility warning. As an
553-
example of this compatibility warning:
554-
555-
```
556-
WARNING: The ProbabilitySampler sampler is presuming TraceIDs are random
557-
and expects the Trace random flag to be set in confirmation. Please
558-
upgrade your caller(s) to use W3C Trace Context Level 2.
559-
```
555+
set](#presumption-of-traceid-randomness) AND an explicit `rv` value is not available in `tracestate`,
556+
the SDK SHOULD NOT include the sampler's `th` value in the OpenTelemetry (`ot`) entry in `tracestate`.
557+
Furthermore, the sampler MUST erase any existing `th` sub-key from the
558+
OpenTelemetry (`ot`) `tracestate` entry.
559+
This is done so downstream processors and connectors can recognize this situation and MUST NOT infer statistical information
560+
from spans sampled using this method.
560561

561562
#### ParentBased
562563

0 commit comments

Comments
 (0)