Skip to content

Commit 5172ff6

Browse files
jmacdkalyanajjpkrohlingNevaytrask
authored
Add specification text for OTEP-0250 (#4466)
Part of #1413 Part of #173 Part of #1060 Part of #1844 ## Prototypes Rust, Go, Java https://github.com/jmacd/rust-sampler https://github.com/jmacd/go-sampler https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/consistent-sampling/src/main/java/io/opentelemetry/contrib/sampler/consistent56 ## Changes Adds specification text for OTEP-0250, which covers CompositeSampler and related interfaces. * [x] Related issues (see above) * [x] Related OTEP 250 (see https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/trace/0250-Composite_Samplers.md) * [x] Links to the prototypes (when adding or changing features) * [x] [`CHANGELOG.md`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/CHANGELOG.md) file updated for non-trivial changes * [x] [`spec-compliance-matrix.md`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/spec-compliance-matrix.md) updated if necessary --------- Co-authored-by: J. Kalyana Sundaram <[email protected]> Co-authored-by: Juraci Paixão Kröhling <[email protected]> Co-authored-by: Tobias Bachert <[email protected]> Co-authored-by: Trask Stalnaker <[email protected]> Co-authored-by: Carlos Alberto Cortez <[email protected]>
1 parent e4c977a commit 5172ff6

File tree

4 files changed

+392
-46
lines changed

4 files changed

+392
-46
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ release.
1111

1212
### Traces
1313

14+
- Define sampling threshold field in OpenTelemetry TraceState; define the behavior
15+
of TraceIdRatioBased sampler in terms of W3C Trace Context Level 2 randomness.
16+
([#4166](https://github.com/open-telemetry/opentelemetry-specification/pull/4166))
17+
- Define CompositeSampler implementation and built-in ComposableSampler interfaces.
18+
([#4466](https://github.com/open-telemetry/opentelemetry-specification/pull/4466))
1419
- Define how SDK implements `Tracer.Enabled`.
1520
([#4537](https://github.com/open-telemetry/opentelemetry-specification/pull/4537))
1621

spec-compliance-matrix.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ formats is required. Implementing more than one format is optional.
8989
| Fetch InstrumentationScope from ReadableSpan | | | + | | + | | | + | | | | |
9090
| [Support W3C Trace Context Level 2 randomness](specification/trace/sdk.md#traceid-randomness) | X | | | | | | | | | | | |
9191
| [TraceIdRatioBased sampler implements OpenTelemetry tracestate `th` field](specification/trace/sdk.md#traceidratiobased) | X | | | | | | | | | | | |
92+
| [CompositeSampler and built-in ComposableSamplers](specification/trace/sdk.md#compositesampler) | X | | | | | | | | | | | |
9293

9394
## Baggage
9495

specification/trace/sdk.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ linkTitle: SDK
3838
- [`TraceIdRatioBased` sampler compatibility warning](#traceidratiobased-sampler-compatibility-warning)
3939
+ [ParentBased](#parentbased)
4040
+ [JaegerRemoteSampler](#jaegerremotesampler)
41+
+ [CompositeSampler](#compositesampler)
42+
- [ComposableSampler](#composablesampler)
43+
* [GetSamplingIntent](#getsamplingintent)
44+
- [Built-in ComposableSamplers](#built-in-composablesamplers)
45+
* [ComposableAlwaysOn](#composablealwayson)
46+
* [ComposableAlwaysOff](#composablealwaysoff)
47+
* [ComposableTraceIDRatioBased](#composabletraceidratiobased)
48+
* [ComposableParentThreshold](#composableparentthreshold)
49+
* [ComposableRuleBased](#composablerulebased)
50+
* [ComposableAnnotating](#composableannotating)
4151
* [Sampling Requirements](#sampling-requirements)
4252
+ [TraceID randomness](#traceid-randomness)
4353
+ [Random trace flag](#random-trace-flag)
@@ -533,6 +543,131 @@ The following configuration properties should be available when creating the sam
533543
[jaeger-remote-sampling-api]: https://www.jaegertracing.io/docs/1.41/architecture/apis/#remote-sampling-configuration-stable
534544
[jaeger-adaptive-sampling]: https://www.jaegertracing.io/docs/1.41/architecture/sampling/#adaptive-sampling
535545

546+
#### CompositeSampler
547+
548+
**Status**: [Development](../document-status.md)
549+
550+
CompositeSampler is a decorator that implements the standard `Sampler` interface but uses a composition of samplers to make its decisions.
551+
552+
The CompositeSampler takes a ComposableSampler as input and delegates the sampling decision to that interface. See [Probability Sampling in TraceState](./tracestate-probability-sampling.md) for more details.
553+
554+
##### ComposableSampler
555+
556+
ComposableSampler is a specialized interface that extends the standard Sampler functionality. It introduces a composable approach to sampling by defining a new method called `GetSamplingIntent`, which allows multiple samplers to work together in making a sampling decision.
557+
558+
###### GetSamplingIntent
559+
560+
Returns a SamplingIntent structure that indicates the sampler's preference for sampling a Span, without actually making the final decision.
561+
562+
**Required arguments:**
563+
564+
* All of the original Sampler API parameters are included
565+
* Parent context, threshold, incoming trace state, and trace flag
566+
information MAY be precomputed so that ComposableSamplers do not
567+
repeatedly probe the Context for this information.
568+
569+
Note: ComposableSamplers MUST NOT modify the parameters passed to
570+
delegate GetSamplingIntent methods, as they are considered read-only
571+
state.
572+
573+
**Return value:**
574+
575+
The method returns a `SamplingIntent` structure with the following elements:
576+
577+
* `threshold` - The sampling threshold value. A lower threshold increases the likelihood of sampling.
578+
* `threshold_reliable` - A boolean indicating if the threshold can be reliably used for
579+
[Span-to-Metrics estimation](./tracestate-probability-sampling.md#sampling-related-terms).
580+
* `attributes_provider` - An optional provider of attributes to be added to the span if it is sampled.
581+
* `trace_state_provider` - An optional provider of a modified TraceState.
582+
583+
Note that `trace_state_provider` may be a significant source of
584+
complexity. ComposableSamplers MUST NOT modify the OpenTelemetry
585+
TraceState (i.e., the `ot` sub-key of TraceState). The calling
586+
CompositeSampler SHOULD update the threshold of the outgoing
587+
TraceState (unless `!threshold_reliable`) and that the explicit
588+
randomness values MUST not be modified.
589+
590+
##### Built-in ComposableSamplers
591+
592+
###### ComposableAlwaysOn
593+
594+
* Always returns a `SamplingIntent` with threshold set to sample all spans (threshold = 0)
595+
* Sets `threshold_reliable` to `true`
596+
* Does not add any attributes
597+
598+
###### ComposableAlwaysOff
599+
600+
* Always returns a `SamplingIntent` with no threshold, indicating all spans should be dropped
601+
* Sets `threshold_reliable` to `false`
602+
* Does not add any attributes
603+
604+
###### ComposableTraceIDRatioBased
605+
606+
* Returns a `SamplingIntent` with threshold determined by the configured sampling ratio
607+
* Sets `threshold_reliable` to `true`
608+
* Does not add any attributes
609+
610+
**Required parameters:**
611+
612+
* `ratio` - A value between `2^-56` and 1.0 (inclusive) representing the desired probability of sampling.
613+
614+
A ratio value of 0 is considered non-probabilistic. For the zero case
615+
a `ComposableAlwaysOff` instance SHOULD be returned instead.
616+
617+
###### ComposableParentThreshold
618+
619+
* For spans without a parent context, delegate to the root sampler
620+
* For spans with a parent context, returns a `SamplingIntent` that propagates the parent's sampling decision
621+
* Returns the parent's threshold if available; otherwise, if the parent's *sampled* flag is set, returns threshold=0; otherwise, if the parent's *sampled* flag is not set, no threshold is returned.
622+
* Sets `threshold_reliable` to match the parent's reliability, which is true if the parent had a threshold.
623+
* Does not add any attributes
624+
625+
**Required parameters:**
626+
627+
* `root` - A delegate for sampling spans without a parent context.
628+
629+
###### ComposableRuleBased
630+
631+
* Evaluates a series of rules based on predicates and returns the `SamplingIntent` from the first matching sampler
632+
* If no rules match, returns a non-sampling intent
633+
634+
**Required parameters:**
635+
636+
* `rules` - A list of (Predicate, ComposableSampler) pairs, where Predicate is a function that evaluates whether a rule applies
637+
638+
###### ComposableAnnotating
639+
640+
* Delegates the sampling decision to another sampler but adds attributes to sampled spans
641+
* Returns a `SamplingIntent` that combines the delegate's threshold with additional attributes
642+
643+
**Required parameters:**
644+
645+
* `attributes` - Attributes to add to sampled spans
646+
* `delegate` - The underlying sampler that makes the actual sampling decision
647+
648+
**Example configuration:**
649+
650+
An example of creating a composite sampler configuration:
651+
652+
```
653+
// Create a rule-based sampler for root spans
654+
rootSampler = ComposableRuleBased([
655+
(isHealthCheck, ComposableAlwaysOff),
656+
(isCheckout, ComposableAlwaysOn),
657+
(isAnything, ComposableTraceIDRatio(0.1))
658+
])
659+
660+
// Create a parent-based sampler for child spans
661+
finalSampler = ComposableParentThreshold(rootSampler)
662+
```
663+
664+
This example creates a configuration where:
665+
666+
- Health check endpoints are never sampled
667+
- Checkout endpoints are always sampled
668+
- Other root spans are sampled at 10%
669+
- Child spans follow their parent's sampling decision
670+
536671
### Sampling Requirements
537672

538673
**Status**: [Development](../document-status.md)

0 commit comments

Comments
 (0)