Skip to content

Commit 08f557b

Browse files
committed
Add the random trace id flag
1 parent 5ddf6db commit 08f557b

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

spec/20-http_request_header_format.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ boolean sampled = (traceFlags & FLAG_SAMPLED) == FLAG_SAMPLED;
138138

139139
##### Sampled flag
140140

141-
The current version of this specification (`00`) only supports a single flag called `sampled`.
142-
143141
When set, the least significant bit (right-most), denotes that the caller may have recorded trace data. When unset, the caller did not record trace data out-of-band.
144142

145143
There are a number of recording scenarios that may break distributed tracing:
@@ -176,6 +174,28 @@ There are two additional options that vendors MAY follow:
176174
- A component that makes a deferred or delayed recording decision may communicate the priority of a recording by setting `sampled` flag to `1` for a subset of requests.
177175
- A component may also fall back to probability sampling and set the `sampled` flag to `1` for the subset of requests.
178176

177+
##### Random Trace ID Flag
178+
179+
<!--
180+
181+
TODO: how many random bytes are needed?
182+
7 was chosen as it can be efficiently represented as a 64-bit signed or unsigned integer.
183+
8 would require an unsigned long which is not supported by some languages (like Java).
184+
63 bits would be possible, but would require a more complex description that may be more difficult to understand.
185+
186+
TODO: Which specific bytes should be random?
187+
The least significant bytes were chosen because some tracing systems are known to use the most significant
188+
portion of the trace id for non-random data such as a timestamp component.
189+
190+
TODO: Do we want to place any restrictions on the randomness or is saying "MUST be random" enough?
191+
As an example, RFC4122 (UUID v4) simply states "Set all the other bits to randomly (or pseudo-randomly) chosen values."
192+
https://datatracker.ietf.org/doc/html/rfc4122#section-4.4
193+
194+
-->
195+
196+
When set, the second least significant bit (second from the right), denotes that the least significant (right-most) 7 bytes of the trace ID MUST be random (or pseudo-random).
197+
When unset, the trace ID may be generated in any way that satisfies the requirements of the [trace ID format](#trace-id).
198+
179199
##### Other Flags
180200

181201
The behavior of other flags, such as (`00000100`) is not defined and is reserved for future use. Vendors MUST set those to zero.

spec/60-trace-id-format.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ concerns](#privacy-considerations) of exposing unwanted information. Randomness
2222
also allows tracing vendors to base sampling decisions on `trace-id` field value
2323
and avoid propagating an additional sampling context.
2424

25+
If the `random-trace-id` flag is set, the least significant 7 bytes of the
26+
`trace-id` MUST be randomly (or pseudo-randomly) generated.
27+
2528
As shown in the next section, it is important for `trace-id` to carry
2629
"uniqueness" and "randomness" in the right part of the `trace-id`, for better
2730
inter-operability with some existing systems.
@@ -50,7 +53,9 @@ systems with these existing systems, the following practices are recommended:
5053
compliant 16 bytes `trace-id` from a shorter identifier, it SHOULD left pad
5154
the original identifier with zeroes. For example, the identifier
5255
`53ce929d0e0e4736`, SHOULD be converted to `trace-id` value
53-
`000000000000000053ce929d0e0e4736`.
56+
`000000000000000053ce929d0e0e4736`. If the resultant `trace-id` value does
57+
not satisfy the constraints of the `random-trace-id` flag, the flag MUST
58+
be set to `0`.
5459
2. When a system receives an inbound message and needs to convert the 16 bytes
5560
`trace-id` to a shorter identifier, the rightmost part of `trace-id` SHOULD
5661
be used as this identifier. For instance, if the value of `trace-id` was

0 commit comments

Comments
 (0)