-
Notifications
You must be signed in to change notification settings - Fork 375
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
Fix manual log injection for 128 bit trace_id #2974
Conversation
1bd4e4f
to
29bf4d2
Compare
@@ -23,7 +23,6 @@ class Identifier | |||
:span_resource, | |||
:span_service, | |||
:span_type, | |||
:trace_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing trace_id
from the public api of this class is problematic.
I think a better solution is to allow trace_id
to continue to be called, but return a string when Datadog.configuration.tracing.trace_id_128_bit_logging_enabled
is true. This means users that opt into this new feature get different behavior, but only after enabling this option setting.
if Datadog.configuration.tracing.trace_id_128_bit_logging_enabled && | ||
!Tracing::Utils::TraceId.to_high_order(@trace_id).zero? | ||
Kernel.format('%032x', @trace_id) | ||
else | ||
Tracing::Utils::TraceId.to_low_order(@trace_id) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this calculation should be repeated for multiple calls of Identifier#trace_id
.
I suggest either moving this to #initialize
and saving the result to trace_id
, or caching it here @trace_id ||= if Datadog.configuration.tracing.trace_id_128_bit_logging_enabled...
.
What does this PR do?
https://docs.datadoghq.com/tracing/trace_collection/dd_libraries/ruby/#for-logging-in-ruby-applications
We exposed
Datadog::Tracing.correlation#trace_id
as public API, which user ends up with different injection result from manual log injection(returning the entire 128 bit trace ID).This PR enforce the coercion of lower 64 bits trace ID on this API to ensure the correctness of manual log injection.