Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpanContext.trace_id is 128 bits and differs from DDtrace implementations in other languages (Node.js, Java, etc.) #8838

Open
thanhj opened this issue Apr 2, 2024 · 4 comments
Assignees

Comments

@thanhj
Copy link

thanhj commented Apr 2, 2024

Summary of problem

In various languages like Java and JavaScript, the dd-trace library stores the 64-bit SpanContext._trace_id, with the additional higher-order bits of the trace ID stored in spanContext._trace.tags['_dd.p.tid']. However, for DDTracePy, the library takes a different approach by combining the 64-bit trace ID from the x-datadog-trace-id header with the higher-order bits from the _dd.p.tid header. Consequently, the SpanContext.trace_id in DDTracePy extends to 128 bits. This discrepancy leads to inconsistencies when attempting to retrieve the trace_id from SpanContext.

In our scenario, we aimed to utilize the trace_id as a uniform identifier for logging across various services. Unfortunately, the varied trace_id lengths across different DDTrace implementations have presented significant challenges for us. To mitigate these issues, we've been compelled to manually adjust the SpanContext.trace_id from 128 bits to 64 bits in all our Python-based services.

Which version of dd-trace-py are you using?

2.x

Which version of pip are you using?

N/A

Which libraries and their versions are you using?

N/A

References:

@emmettbutler
Copy link
Collaborator

Thanks for pointing this out, @thanhj.

cc @ZStriker19

@ZStriker19
Copy link
Contributor

Hi @thanhj, one option for you could be to do something similar to this method whenever you grab the context.span_id. Just basically always make sure you're injecting the lower 64 bits into your logs to correlate. Would that work for your use case?

@ZStriker19 ZStriker19 self-assigned this Apr 5, 2024
@thanhj
Copy link
Author

thanhj commented Apr 5, 2024

Hi @ZStriker19,
I didn't mean to find a workaround solution, as we already did it by shifting from 128-bit to 64-bit str((1 << 64) - 1 & context.trace_id).
However, I would suggest to treat the trace_id consistent to 64-bit to align with the other languages.

@kevin-ip
Copy link

Setting DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED to false seems updating the trace ID to 64-bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants