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

Fix manual log injection for 128 bit trace_id #2974

Merged
merged 1 commit into from
Jul 24, 2023

Conversation

TonyCTHsu
Copy link
Contributor

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.

@TonyCTHsu TonyCTHsu requested a review from a team July 17, 2023 12:09
@TonyCTHsu TonyCTHsu changed the title Fix trace_id logging Fix manual log injection for 128 bit trace_id Jul 17, 2023
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/fix-logging-trace-id branch from 1bd4e4f to 29bf4d2 Compare July 17, 2023 12:11
@TonyCTHsu TonyCTHsu added this to the 1.13.0 milestone Jul 17, 2023
@@ -23,7 +23,6 @@ class Identifier
:span_resource,
:span_service,
:span_type,
:trace_id,
Copy link
Member

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.

Comment on lines +75 to 81
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
Copy link
Member

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

@TonyCTHsu TonyCTHsu merged commit 31faddb into master Jul 24, 2023
@TonyCTHsu TonyCTHsu deleted the tonycthsu/fix-logging-trace-id branch July 24, 2023 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants