@@ -92,21 +92,38 @@ Implementation may decide to completely ignore the traceparent when the span-id
92
92
93
93
## Trace-options
94
94
95
- Controls tracing options such as sampling, trace level etc. It is a 1 byte representing an 8-bit
96
- unsigned integer. The flags are recommendations given by the caller rather than strict rules to
97
- follow for three reasons:
95
+ An [ 8-bit field ] ( https://en.wikipedia.org/wiki/Bit_field ) that controls tracing options such
96
+ as sampling, trace level etc. These flags are recommendations given by the caller rather than
97
+ strict rules to follow for three reasons:
98
98
99
99
1 . Trust and abuse.
100
100
2 . Bug in caller
101
101
3 . Different load between caller service and callee service might force callee to down sample.
102
102
103
+ Like other fields, ` trace-options ` is hex-encoded. For example, all 8 flags set would be 'ff'
104
+ and no flags set would be '00'.
105
+
106
+ As this is a bit field, you cannot interpret flags by decoding the hex value and looking at
107
+ the resulting number. For example, a flag ` 00000001 ` could be encoded as ` 01 ` in hex, or ` 09 `
108
+ in hex if present with the flag ` 00001000 ` . A common mistake in bit fields is forgeting to
109
+ mask when interpreting flags.
110
+
111
+ Here is an example of properly handing trace options:
112
+ ``` java
113
+ static final int FLAG_TRACED = 1 << 1 ; // 00000001
114
+ ...
115
+ boolean traced = (traceOptions & FLAG_TRACED ) == FLAG_TRACED
116
+ ```
117
+
103
118
### Bits behavior definition
119
+ When the ` trace-options ` field is missing, flags are interpreted as unset.
120
+
121
+ #### Traced Flag (00000001)
122
+ When set, the least significant bit recommends the request should be traced. A caller who
123
+ defers a tracing decision leaves this flag unset.
104
124
105
- * The least significant bit (the 7th bit) provides recommendation whether the request should be
106
- traced or not (` 1 ` recommends the request should be traced, ` 0 ` means the caller does not
107
- make a decision to trace and the decision might be deferred). When ` trace-options ` is missing
108
- the default value for this bit is ` 0 `
109
- * The behavior of other bits is currently undefined.
125
+ #### Other Flags
126
+ The behavior of other flags, such as (00000010) are undefined.
110
127
111
128
## Examples of HTTP headers
112
129
0 commit comments