You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
*`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:
0 commit comments