As part of parsing the w3C traceparent header, the library attempts to extract the trace_sampled flag out of the FLAGS_PART of the header. It uses the following logic to check if the field is set:
traceSampled: parseInt(match[4], 16) === 1,
The issue is that the FLAG_PART is meant to be a bit field, and may contain other flags. From the spec:
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
To solve the issue, the traceSampled logic should check the right-most bit of the number, instead of checking if the number == 1. We should be able to do something like this instead:
traceSampled: bool(parseInt(match[4], 16) & 1),
As part of parsing the w3C traceparent header, the library attempts to extract the trace_sampled flag out of the FLAGS_PART of the header. It uses the following logic to check if the field is set:
The issue is that the FLAG_PART is meant to be a bit field, and may contain other flags. From the spec:
To solve the issue, the traceSampled logic should check the right-most bit of the number, instead of checking if the number == 1. We should be able to do something like this instead: