Skip to content

Commit 59c0089

Browse files
adriancoleSergey Kanzhelev
authored andcommitted
Clarifies that trace options is a bit field (#116)
* Clarifies that trace options is a bit field See #8 (comment) * simplify sentence
1 parent 1c5a7bf commit 59c0089

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

trace_context/HTTP_HEADER_FORMAT.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,38 @@ Implementation may decide to completely ignore the traceparent when the span-id
9292

9393
## Trace-options
9494

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:
9898

9999
1. Trust and abuse.
100100
2. Bug in caller
101101
3. Different load between caller service and callee service might force callee to down sample.
102102

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+
103118
### 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.
104124

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.
110127

111128
## Examples of HTTP headers
112129

0 commit comments

Comments
 (0)