-
Notifications
You must be signed in to change notification settings - Fork 897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenTelemetry TraceIdRatioBased sampler requirements following OTEP 235 #4166
Draft
jmacd
wants to merge
37
commits into
open-telemetry:main
Choose a base branch
from
jmacd:jmacd/otep235
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 25 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0524a3d
OpenTelemetry trace SDK requirements for probability sampling followi…
jmacd c5453f8
linebreaks
jmacd 25a61fd
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd 68fa270
Add a migration section
jmacd 51f9794
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd ba5a47b
lowercase hex
jmacd 49673b7
spec-compliance-matrix.md
jmacd e51bea6
merge w/ removed file
jmacd 4afe1c7
chlog
jmacd 2f0dc0b
reverse inequality
jmacd f333b71
Apply suggestions from code review
jmacd b7376bd
remove sci-note and reverse region
jmacd 483b3fa
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd c40de50
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd 15a9c6f
spec-compliance: AlwaysOn too
jmacd 672fac2
edits for jpkrohling
jmacd 3c80d97
Apply suggestions from code review
jmacd b2b37f7
Merge branch 'jmacd/otep235' of github.com:jmacd/opentelemetry-specif…
jmacd 1bb0b31
algorithm
jmacd 2f0e387
move a sentence; drop a paragraph
jmacd 6e29b0e
more overview
jmacd 77b51f8
nuance
jmacd a61fbdd
Update specification/trace/tracestate-probability-sampling.md
jmacd 59c329d
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd d21f341
Merge branch 'jmacd/otep235' of github.com:jmacd/opentelemetry-specif…
jmacd 4e05267
Apply suggestions from code review
jmacd d65ea09
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd 92876f9
Use consistent terminology with 4162, e.g., OpenTelemetry TraceState …
jmacd 1855839
Specify a compatibility warning for transition
jmacd 44c8190
asymmetrical
jmacd 66d190f
TOC
jmacd 0aacc19
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd e6dc409
AlwaysOn should respect sampling threshold
jmacd c75a010
Revert "AlwaysOn should respect sampling threshold"
jmacd 87fb314
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd f3693fc
do not change AlwaysOnSampler spec
jmacd b0a840a
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,9 @@ linkTitle: SDK | |
+ [AlwaysOn](#alwayson) | ||
+ [AlwaysOff](#alwaysoff) | ||
+ [TraceIdRatioBased](#traceidratiobased) | ||
- [Requirements for `TraceIdRatioBased` sampler algorithm](#requirements-for-traceidratiobased-sampler-algorithm) | ||
- [`TraceIdRatioBased` sampler configuration](#traceidratiobased-sampler-configuration) | ||
- [`TraceIdRatioBased` sampler algorithm](#traceidratiobased-sampler-algorithm) | ||
- [`TraceIdRatioBased` sampler description](#traceidratiobased-sampler-description) | ||
+ [ParentBased](#parentbased) | ||
+ [JaegerRemoteSampler](#jaegerremotesampler) | ||
- [Span Limits](#span-limits) | ||
|
@@ -372,12 +374,23 @@ Callers SHOULD NOT cache the returned value. | |
### Built-in samplers | ||
|
||
OpenTelemetry supports a number of built-in samplers to choose from. | ||
The default sampler is `ParentBased(root=AlwaysOn)`. | ||
|
||
The default sampler is `ParentBased(root=AlwaysOn)`, which configures | ||
a policy depending on whether the new span is a root or a child: | ||
|
||
* For root spans, always sample a new context. | ||
* For child spans, take the decision of the parent context. | ||
|
||
By using the ParentBased sampler by default, users can change sampling | ||
across their system by reconfiguring only root span Samplers. To | ||
configure probability-based trace sampling across a system, users may | ||
configure `ParentBased(root=TraceIdRatioBased{probability})`. | ||
|
||
#### AlwaysOn | ||
|
||
* Returns `RECORD_AND_SAMPLE` always. | ||
* Description MUST be `AlwaysOnSampler`. | ||
* OpenTelemetry TraceState SHOULD include `th:0`. | ||
|
||
#### AlwaysOff | ||
|
||
|
@@ -386,40 +399,48 @@ The default sampler is `ParentBased(root=AlwaysOn)`. | |
|
||
#### TraceIdRatioBased | ||
jmacd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* The `TraceIdRatioBased` MUST ignore the parent `SampledFlag`. To respect the | ||
parent `SampledFlag`, the `TraceIdRatioBased` should be used as a delegate of | ||
the `ParentBased` sampler specified below. | ||
* Description MUST return a string of the form `"TraceIdRatioBased{RATIO}"` | ||
with `RATIO` replaced with the Sampler instance's trace sampling ratio | ||
represented as a decimal number. The precision of the number SHOULD follow | ||
implementation language standards and SHOULD be high enough to identify when | ||
Samplers have different ratios. For example, if a TraceIdRatioBased Sampler | ||
had a sampling ratio of 1 to every 10,000 spans it COULD return | ||
`"TraceIdRatioBased{0.000100}"` as its description. | ||
|
||
TODO: Add details about how the `TraceIdRatioBased` is implemented as a function | ||
of the `TraceID`. [#1413](https://github.com/open-telemetry/opentelemetry-specification/issues/1413) | ||
|
||
##### Requirements for `TraceIdRatioBased` sampler algorithm | ||
|
||
* The sampling algorithm MUST be deterministic. A trace identified by a given | ||
`TraceId` is sampled or not independent of language, time, etc. To achieve this, | ||
implementations MUST use a deterministic hash of the `TraceId` when computing | ||
the sampling decision. By ensuring this, running the sampler on any child `Span` | ||
will produce the same decision. | ||
* A `TraceIdRatioBased` sampler with a given sampling rate MUST also sample all | ||
traces that any `TraceIdRatioBased` sampler with a lower sampling rate would | ||
sample. This is important when a backend system may want to run with a higher | ||
sampling rate than the frontend system, this way all frontend traces will | ||
still be sampled and extra traces will be sampled on the backend only. | ||
* **WARNING:** Since the exact algorithm is not specified yet (see TODO above), | ||
there will probably be changes to it in any language SDK once it is, which | ||
would break code that relies on the algorithm results. | ||
Only the configuration and creation APIs can be considered stable. | ||
It is recommended to use this sampler algorithm only for root spans | ||
(in combination with [`ParentBased`](#parentbased)) because different language | ||
SDKs or even different versions of the same language SDKs may produce inconsistent | ||
results for the same input. | ||
The `TraceIdRatioBased` sampler implements simple, ratio-based probability sampling using randomness features specified in the [W3C Trace Context Level 2][W3CCONTEXTMAIN] Candidate Recommendation. | ||
jmacd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
OpenTelemetry follows W3C Trace Context Level 2, which specifies 56 bits of randomness, in making use of 56 bits of information for probabilistic sampling decisions. | ||
jmacd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[OpenTelemetry defines consistent probability sampling using 56 bits of randomness][CONSISTENTSAMPLING]. | ||
|
||
The `TraceIdRatioBased` sampler MUST ignore the parent `SampledFlag`. | ||
For respecting the parent `SampledFlag`, see the `ParentBased` sampler specified below. | ||
jmacd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Note that the "ratio-based" part of this Sampler's name implies that | ||
it makes a probability decision directly from the TraceID, even though | ||
it was not not originally specified in an exact way. In the present | ||
jmacd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
specification,the Sampler decision is more nuanced: only a portion of | ||
jmacd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
the identifier is used, after checking whether the OpenTelemetry | ||
TraceState field contains an explicit trace randomness value. | ||
|
||
[W3CCONTEXTMAIN]: https://www.w3.org/TR/trace-context-2 | ||
|
||
##### `TraceIdRatioBased` sampler configuration | ||
|
||
The `TraceIdRatioBased` sampler is typically configured using a 32-bit or 64-bit floating point number to express the sampling ratio. | ||
The minimum valid sampling ratio is `2^-56`, and the maximum valid sampling ratio is 1.0. | ||
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. | ||
|
||
[CONSISTENTSAMPLING]: ./tracestate-probability-sampling.md | ||
|
||
##### `TraceIdRatioBased` sampler algorithm | ||
|
||
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`. | ||
|
||
* If randomness value (R) is greater or equal to the rejection threshold (T), meaning when (R >= T), return `RECORD_AND_SAMPLE`, otherwise, return `DROP`. | ||
* 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]. | ||
Comment on lines
+418
to
+421
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note there is a simple change needed here, following #4321. The TraceIDRatio sampler is a composable sampler in the sense defined there, where it simply returns its |
||
|
||
[TRACESTATEHANDLING]: ./tracestate-handling.md#sampling-threshold-value-th | ||
|
||
##### `TraceIdRatioBased` sampler description | ||
|
||
The `TraceIdRatioBased` GetDescription MUST return a string of the form `"TraceIdRatioBased{RATIO}"` | ||
with `RATIO` replaced with the Sampler instance's trace sampling ratio | ||
represented as a decimal number. The precision of the number SHOULD follow | ||
implementation language standards and SHOULD be high enough to identify when | ||
Samplers have different ratios. For example, if a TraceIdRatioBased Sampler | ||
had a sampling ratio of 1 to every 10,000 spans it could return | ||
`"TraceIdRatioBased{0.000100}"` as its description. | ||
jmacd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### ParentBased | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this should be an "aside" or non-normative callout. I'm not sure we have precedence here, but could you move this to some different markdown structure, perhaps
> quote
?