Skip to content
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

Randomness requirements following W3C Trace Context level 2 #4162

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
71750cd
rebase
jmacd Jul 29, 2024
3c4b8fa
line breaks
jmacd Jul 30, 2024
a73e378
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Aug 7, 2024
c174e36
revise trace randomness requirements for clarity
jmacd Aug 7, 2024
93dcd7a
Apply suggestions from code review
jmacd Aug 7, 2024
76c6c71
clarify which contexts for each requirement
jmacd Aug 7, 2024
d1784fa
Merge branch 'jmacd/sampling_new' of github.com:jmacd/opentelemetry-s…
jmacd Aug 7, 2024
b9ec958
user-defined explicit randomness: may
jmacd Aug 7, 2024
6a2d6c5
lowercase hex only
jmacd Aug 7, 2024
01d5aac
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Aug 15, 2024
6d8f30d
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Aug 29, 2024
2fbd8b2
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Sep 12, 2024
56d8e26
Clarify when tracestate and traceparent are propagated
jmacd Sep 12, 2024
7489914
tracing-system-specific, not vendor
jmacd Sep 12, 2024
6ad9842
idgenerator randomness
jmacd Sep 12, 2024
47d3132
marker interface
jmacd Sep 12, 2024
bfa4ca2
changelog fix
jmacd Sep 12, 2024
7165596
2 revisions
jmacd Oct 2, 2024
22933c7
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Oct 2, 2024
a6a4d11
spec is optional
jmacd Oct 2, 2024
140492b
API for explicit trace randomness
jmacd Oct 2, 2024
c684e61
revert chlog
jmacd Oct 3, 2024
d92643b
revise to limit explicit randomness difficulty
jmacd Oct 3, 2024
b98a4d0
toc
jmacd Oct 4, 2024
de2a422
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Oct 10, 2024
6b53a20
Apply suggestions from code review
jmacd Oct 21, 2024
1c07f76
Status: development; reword IdGenerator randomness requirement
jmacd Oct 21, 2024
7dc6fca
Merge branch 'jmacd/sampling_new' of github.com:jmacd/opentelemetry-s…
jmacd Oct 21, 2024
61ad71c
clarify alternate SDK requirements
jmacd Oct 21, 2024
712cd41
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Oct 21, 2024
ba7114e
whitespace
jmacd Oct 21, 2024
f336fb1
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Oct 30, 2024
b75113c
From Peter's feedback: Root samplers MAY set explicit randomness. SDK…
jmacd Oct 30, 2024
1376b9d
Merge branch 'main' of github.com:open-telemetry/opentelemetry-specif…
jmacd Nov 13, 2024
0ed30ef
editorial
jmacd Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ release.
([#4137](https://github.com/open-telemetry/opentelemetry-specification/pull/4137))
- Add in-development `OnEnding` callback to SDK `SpanProcessor` interface.
([#4024](https://github.com/open-telemetry/opentelemetry-specification/pull/4024))
- Define randomness value requirements for W3C Trace Context Level 2.
([#4162](https://github.com/open-telemetry/opentelemetry-specification/pull/4162))

### Metrics

Expand Down
2 changes: 2 additions & 0 deletions spec-compliance-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ formats is required. Implementing more than one format is optional.
| [Built-in `SpanProcessor`s implement `ForceFlush` spec](specification/trace/sdk.md#forceflush-1) | | | + | | + | + | + | + | + | + | + | |
| [Attribute Limits](specification/common/README.md#attribute-limits) | X | | + | | + | + | + | + | | | | |
| Fetch InstrumentationScope from ReadableSpan | | | + | | + | | | + | | | | |
| TraceID generator implements W3C Trace Context Level 2 randomness | | | | | | | | | | | | |
jmacd marked this conversation as resolved.
Show resolved Hide resolved
| OpenTelemetry explicit randomness supported | X | | | | | | | | | | | |

## Baggage

Expand Down
12 changes: 12 additions & 0 deletions specification/context/api-propagators.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* [Get Global Propagator](#get-global-propagator)
* [Set Global Propagator](#set-global-propagator)
- [Propagators Distribution](#propagators-distribution)
* [W3C Trace Context Requirements](#w3c-trace-context-requirements)
* [B3 Requirements](#b3-requirements)
+ [B3 Extract](#b3-extract)
+ [B3 Inject](#b3-inject)
Expand Down Expand Up @@ -355,6 +356,17 @@ Additional `Propagator`s implementing vendor-specific protocols such as AWS
X-Ray trace header protocol MUST NOT be maintained or distributed as part of
the Core OpenTelemetry repositories.

### W3C Trace Context Requirements

A W3C Trace Context propagator is expected to implement the `traceparent` and `tracestate` contexts fields specified in [W3C Trace Context Level 2](https://www.w3.org/TR/trace-context-2/).
jmacd marked this conversation as resolved.
Show resolved Hide resolved
jmacd marked this conversation as resolved.
Show resolved Hide resolved

When injecting and extracting trace context to or from a carrier, the following fields from the `SpanContext` are propagated.

- TraceID (16 bytes)
- SpanID (8 bytes)
- TraceFlags (8 bits)
- TraceState (string)

### B3 Requirements

B3 has both single and multi-header encodings. It also has semantics that do not
Expand Down
21 changes: 11 additions & 10 deletions specification/trace/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,17 @@ non-zero byte.
`SpanId` A valid span identifier is an 8-byte array with at least one non-zero
byte.

`TraceFlags` contain details about the trace. Unlike TraceState values,
TraceFlags are present in all traces. The current version of the specification
only supports a single flag called [sampled](https://www.w3.org/TR/trace-context/#sampled-flag).

`TraceState` carries vendor-specific trace identification data, represented as a list
of key-value pairs. TraceState allows multiple tracing
systems to participate in the same trace. It is fully described in the [W3C Trace Context
specification](https://www.w3.org/TR/trace-context/#tracestate-header). For
specific OTel values in `TraceState`, see the [TraceState Handling](tracestate-handling.md)
document.
`TraceFlags` contain details about the trace.
Unlike TraceState values, TraceFlags are present in all traces.
The current version of the specification supports two flags:

- [Sampled](https://www.w3.org/TR/trace-context-2/#sampled-flag)
- [Random](https://www.w3.org/TR/trace-context-2/#random-trace-id-flag)
jmacd marked this conversation as resolved.
Show resolved Hide resolved

`TraceState` carries vendor-specific trace identification data, represented as a list of key-value pairs.
jmacd marked this conversation as resolved.
Show resolved Hide resolved
TraceState allows multiple tracing systems to participate in the same trace.
It is fully described in the [W3C Trace Context specification](https://www.w3.org/TR/trace-context-2/#tracestate-header).
For specific OpenTelemetry values in `TraceState`, see the [TraceState Handling](tracestate-handling.md) document.

`IsRemote`, a boolean indicating whether the SpanContext was received from somewhere
else or locally generated, see [IsRemote](#isremote).
Expand Down
63 changes: 62 additions & 1 deletion specification/trace/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ linkTitle: SDK
- [Sampling](#sampling)
* [Recording Sampled reaction table](#recording-sampled-reaction-table)
* [SDK Span creation](#sdk-span-creation)
+ [Span flags](#span-flags)
* [Sampler](#sampler)
+ [ShouldSample](#shouldsample)
+ [GetDescription](#getdescription)
Expand All @@ -33,6 +34,13 @@ linkTitle: SDK
- [Requirements for `TraceIdRatioBased` sampler algorithm](#requirements-for-traceidratiobased-sampler-algorithm)
+ [ParentBased](#parentbased)
+ [JaegerRemoteSampler](#jaegerremotesampler)
* [Sampling Requirements](#sampling-requirements)
+ [TraceID randomness](#traceid-randomness)
+ [Random trace flag](#random-trace-flag)
+ [Explicit trace randomness](#explicit-trace-randomness)
+ [Presumption of TraceID randomness](#presumption-of-traceid-randomness)
+ [User-defined explicit trace randomness](#user-defined-explicit-trace-randomness)
+ [IdGenerator randomness](#idgenerator-randomness)
- [Span Limits](#span-limits)
- [Id Generators](#id-generators)
- [Span processor](#span-processor)
Expand Down Expand Up @@ -265,7 +273,7 @@ The OpenTelemetry API has two properties responsible for the data collection:
receive them unless the `Sampled` flag was also set.
* `Sampled` flag in `TraceFlags` on `SpanContext`. This flag is propagated via
the `SpanContext` to child Spans. For more details see the [W3C Trace Context
specification](https://www.w3.org/TR/trace-context/#sampled-flag). This flag indicates that the `Span` has been
specification][W3CCONTEXTSAMPLEDFLAG]. This flag indicates that the `Span` has been
`sampled` and will be exported. [Span Exporters](#span-exporter) MUST
receive those spans which have `Sampled` flag set to true and they SHOULD NOT receive the ones
that do not.
Expand Down Expand Up @@ -316,6 +324,14 @@ When asked to create a Span, the SDK MUST act as if doing the following in order
`Span` is created without an SDK installed or as described in
[wrapping a SpanContext in a Span](api.md#wrapping-a-spancontext-in-a-span).
jmacd marked this conversation as resolved.
Show resolved Hide resolved

#### Span flags

The OTLP representation for Span and Span Link include a 32-bit field declared as Span Flags.
jmacd marked this conversation as resolved.
Show resolved Hide resolved

Bits 0-7 of the Span Flags field are reserved for the 8 bits of Trace Context flags,
jmacd marked this conversation as resolved.
Show resolved Hide resolved
specified in the [W3C Trace Context Level 2][W3CCONTEXTMAIN] Candidate Recommendation.
[See the list of recognized flags](./api.md#spancontext).

jmacd marked this conversation as resolved.
Show resolved Hide resolved
### Sampler

`Sampler` interface allows users to create custom samplers which will return a
Expand Down Expand Up @@ -466,6 +482,51 @@ The following configuration properties should be available when creating the sam
[jaeger-remote-sampling-api]: https://www.jaegertracing.io/docs/1.41/apis/#remote-sampling-configuration-stable
[jaeger-adaptive-sampling]: https://www.jaegertracing.io/docs/1.41/sampling/#adaptive-sampling

### Sampling Requirements

jmacd marked this conversation as resolved.
Show resolved Hide resolved
The [W3C Trace Context Level 2][W3CCONTEXTMAIN] Candidate Recommendation includes [a Random trace flag][W3CCONTEXTRANDOMFLAG] for indicating that the TraceID contains 56 random bits, specified for statistical purposes.
jmacd marked this conversation as resolved.
Show resolved Hide resolved
This flag indicates that [the least-significant ("rightmost") 7 bytes or 56 bits of the TraceID are random][W3CCONTEXTTRACEID].

Note the Random flag does not propagate through [Trace Context Level 1][W3CCONTEXTLEVEL1] implementations, which do not recognize the flag.
Therefore, this flag is considered meaningful only when it is set on a root span context.
jmacd marked this conversation as resolved.
Show resolved Hide resolved
To enable sampling in this and other situations where TraceIDs lack sufficient randomness,
OpenTelemetry defines an optional [explicit randomness value][OTELRVALUE] encoded in the [W3C TraceState field][W3CCONTEXTTRACESTATE].

This specification recommends the use of either TraceID randomness or explicit trace randomness,
which ensures that samplers always have sufficient randomness when using W3C Trace Context propagation.

[W3CCONTEXTMAIN]: https://www.w3.org/TR/trace-context-2
[W3CCONTEXTLEVEL1]: https://www.w3.org/TR/trace-context
[W3CCONTEXTTRACEID]: https://www.w3.org/TR/trace-context-2/#randomness-of-trace-id
[W3CCONTEXTTRACESTATE]: https://www.w3.org/TR/trace-context-2/#tracestate-header
[W3CCONTEXTSAMPLEDFLAG]: https://www.w3.org/TR/trace-context-2/#sampled-flag
[W3CCONTEXTRANDOMFLAG]: https://www.w3.org/TR/trace-context-2/#random-trace-id-flag
[OTELRVALUE]: ./tracestate-handling.md#explicit-randomness-value-rv

#### TraceID randomness

The SDK SHOULD implement the TraceID randomness requirements specified in the [W3C Trace Context Level 2][W3CCONTEXTTRACEID] Candidate Recommendation when generating TraceID values.

#### Random trace flag

The Trace Context `Random` flag SHOULD be set in the W3C Trace Context instantiated by the SDK when it generates a TraceID meeting the [W3C Trace Context Level 2 randomness requirements][W3CCONTEXTTRACEID].

#### Explicit trace randomness

When the trace SDK creates a root span context and the TraceID lacks randomness (i.e., the Random flag could not be set), the SDK SHOULD insert explicit randomness using the [`rv` sub-key of the OpenTelemetry TraceState][OTELRVALUE].

#### Presumption of TraceID randomness

Because explicit randomness values offer a mechanism for sampling TraceIDs without sufficient randomness, OpenTelemetry samplers MUST presume that TraceIDs include sufficient randomness when an explicit randomness value is not present.

#### User-defined explicit trace randomness

Trace SDKs SHOULD permit users to setup explicit randomness before creating a root span by entering it into the SpanContext TraceState before creating a root span. This lets users enable consistent sampling across traces.

#### IdGenerator randomness

If the SDK uses an `IdGenerator` extension point, the SDK SHOULD enable it to declare whether it meets the Randomness requirement in order to set the random trace flag.
jmacd marked this conversation as resolved.
Show resolved Hide resolved

## Span Limits

Span attributes MUST adhere to the [common rules of attribute limits](../common/README.md#attribute-limits).
Expand Down
24 changes: 24 additions & 0 deletions specification/trace/tracestate-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,27 @@ if ok {
// traceState was not updated.
}
```

## Pre-defined OpenTelemetry sub-keys
jmacd marked this conversation as resolved.
Show resolved Hide resolved

The following values have been defined by OpenTelemetry.

### Explicit randomness value `rv`

The OpenTelemetry TraceState `rv` sub-key defines an alternative source of randomness to the use of TraceID randomness when used by samplers decisions.
Values of `rv` MUST be exactly 14 hexadecimal digits:

```
hexdigit = DIGIT ; A-F ; a-f
jmacd marked this conversation as resolved.
Show resolved Hide resolved
```

The explicit randomness value is meant to be used instead of extracting randomness from TraceIDs, therefore it contains the same number of bits as a W3C Trace Context Level 2 recommends for TraceIDs.
jmacd marked this conversation as resolved.
Show resolved Hide resolved
jmacd marked this conversation as resolved.
Show resolved Hide resolved

Explicit randomness values are meant to propagate through [span contexts](../context/README.md) unmodified.
Explicit randomness values SHOULD NOT be erased from the OpenTelemetry TraceState or modified once associated with a new TraceID, so that sampling decisions made using the explicit randomness value are consistent across signals.

For example, here is a W3C TraceState values including an OpenTelemetry explicit randomness value:
jmacd marked this conversation as resolved.
Show resolved Hide resolved

```
tracestate: ot=rv:6e6d1a75832a2f
```
Loading