Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

traceparent traceSampled parsing issue #1188

@daniel-sanche

Description

@daniel-sanche

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),

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/nodejs-logging API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions