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
* Add the random trace id flag
* Wording
* Wording
Co-authored-by: Yuri Shkuro <[email protected]>
* Add SHOULD wording to trace id randomness
* Specify that implementers SHOULD set random flag when appropriate
* Random flag means at least 7 bytes
* Flag wording
* Only 2 flags are specified
* Remove redundant wording
* At least 7 bytes
* Review comments
* Remove RECOMMENDED wording
Co-authored-by: Yuri Shkuro <[email protected]>
Co-authored-by: Yuri Shkuro <[email protected]>
Copy file name to clipboardExpand all lines: spec/20-http_request_header_format.md
+27-8
Original file line number
Diff line number
Diff line change
@@ -100,13 +100,17 @@ trace-flags = 2HEXDIGLC ; 8 bit flags. Currently, only one bit is used. S
100
100
101
101
#### trace-id
102
102
103
-
This is the ID of the whole trace forest and is used to uniquely identify a <ahref="#dfn-distributed-traces">distributed trace</a> through a system. It is represented as a 16-byte array, for example, `4bf92f3577b34da6a3ce929d0e0e4736`. All bytes as zero (`00000000000000000000000000000000`) is considered an invalid value.
103
+
This is the ID of the whole trace forest and is used to uniquely identify a <ahref="#dfn-distributed-traces">distributed trace</a> through a system.
104
+
It is represented as a 16-byte array, for example, `4bf92f3577b34da6a3ce929d0e0e4736`.
105
+
All bytes as zero (`00000000000000000000000000000000`) is considered an invalid value.
104
106
105
-
If the `trace-id` value is invalid (for example if it contains non-allowed characters or all zeros), vendors MUST ignore the `traceparent`.
107
+
The value of `trace-id` SHOULD be globally unique.
108
+
One recommended method to ensure global uniqueness, as well as to address some privacy and security considerations, to a satisfactory degree of certainty is to randomly (or pseudo-randomly) generate the `trace-id`.
109
+
Implementers SHOULD use a `trace-id` generation method which randomly (or pseudo-randomly) generates at least the right-most 7 bytes of the ID.
110
+
If the right-most 7 bytes are randomly (or pseudo-randomly) generated, the corresponding [random trace id flag](#random-trace-id-flag) SHOULD be set.
111
+
For more details, see [considerations for trace-id field generation](#considerations-for-trace-id-field-generation).
106
112
107
-
See [considerations for trace-id field
108
-
generation](#considerations-for-trace-id-field-generation) for recommendations
109
-
on how to operate with `trace-id`.
113
+
If the `trace-id` value is invalid (for example if it contains non-allowed characters or all zeros), vendors MUST ignore the `traceparent`.
110
114
111
115
#### parent-id
112
116
@@ -116,6 +120,8 @@ Vendors MUST ignore the `traceparent` when the `parent-id` is invalid (for examp
116
120
117
121
#### trace-flags
118
122
123
+
The current version of this specification (`00`) supports only two flags: `sampled` and `random-trace-id`.
124
+
119
125
An <adata-cite='!BIT-FIELD#firstHeading'>8-bit field</a> that controls tracing flags such as sampling, trace level, etc. These flags are recommendations given by the caller rather than strict rules to follow for three reasons:
120
126
121
127
1. An untrusted caller may be able to abuse a tracing system by setting these flags maliciously.
@@ -126,20 +132,22 @@ You can find more in the section [Security considerations](#security-considerati
126
132
127
133
Like other fields, `trace-flags` is hex-encoded. For example, all `8` flags set would be `ff` and no flags set would be `00`.
128
134
129
-
As this is a bit field, you cannot interpret flags by decoding the hex value and looking at the resulting number. For example, a flag `00000001` could be encoded as `01` in hex, or `09` in hex if present with the flag `00001000`. A common mistake in bit fields is forgetting to mask when interpreting flags.
135
+
As this is a bit field, the flags cannot be interpreted by a simple equality comparison.
136
+
For example, both `01` (`00000001`) and `03` (`00000011`) represent that the trace has been sampled because the sampled flag (`00000001`) is set, and `03` and `02` (`00000010`) both represent that at least the right-most 7 bytes of the `trace-id` are randomly (or pseudo-randomly) generated because the random bit (`00000010`) is set.
137
+
A common mistake when interpreting bit-fields is using a comparison of the whole number rather than interpreting a single bit.
130
138
131
139
Here is an example of properly handling trace flags:
boolean random = (traceFlags &FLAG_RANDOM) ==FLAG_RANDOM;
137
147
```
138
148
139
149
##### Sampled flag
140
150
141
-
The current version of this specification (`00`) only supports a single flag called `sampled`.
142
-
143
151
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.
144
152
145
153
There are a number of recording scenarios that may break distributed tracing:
@@ -176,6 +184,17 @@ There are two additional options that vendors MAY follow:
176
184
- 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.
177
185
- A component may also fall back to probability sampling and set the `sampled` flag to `1` for the subset of requests.
178
186
187
+
##### Random Trace ID Flag
188
+
189
+
The second least significant bit of the trace-flags field denotes the random-trace-id flag.
190
+
If that flag is set, at least the right-most 7 bytes of the trace ID MUST be random (or pseudo-random).
191
+
If the flag is not set, the trace ID MAY still be randomly (or pseudo-randomly) generated.
192
+
When unset, the trace ID MAY be generated in any way that satisfies the requirements of the [trace ID format](#trace-id).
193
+
194
+
When at least the right-most 7 bytes of the `trace-id` are randomly (or pseudo-randomly) generated, the random trace ID flag SHOULD be set to `1`.
195
+
This allows downstream consumers to implement features such as trace sampling or database sharding based on these bytes.
196
+
For additional information, see [considerations for trace-id field generation](#considerations-for-trace-id-field-generation).
197
+
179
198
##### Other Flags
180
199
181
200
The behavior of other flags, such as (`00000100`) is not defined and is reserved for future use. Vendors MUST set those to zero.
0 commit comments