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

Return string for trace_id and span_id from Correlation::Identifier #3322

Merged
merged 8 commits into from
Jan 26, 2024

Conversation

TonyCTHsu
Copy link
Contributor

@TonyCTHsu TonyCTHsu commented Dec 12, 2023

2.0 Upgrade Guide notes

When manually correlating logs with Datadog::Tracing.correlation.trace_id and Datadog::Tracing.correlation.span_id, make sure to check if your usage still compatible after returning string instead of integer.

🚨 Breaking changes: Other fields(except service, env, version, trace_id and span_id) removed.

What does this PR do?

Return string for trace_id and span_id from Correlation::Identifier

Remove other fields that are not consider public API.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@TonyCTHsu TonyCTHsu added the breaking-change Involves a breaking change label Dec 12, 2023
@TonyCTHsu TonyCTHsu marked this pull request as ready for review December 12, 2023 14:15
@TonyCTHsu TonyCTHsu requested a review from a team as a code owner December 12, 2023 14:15
@TonyCTHsu TonyCTHsu self-assigned this Dec 12, 2023
@codecov-commenter
Copy link

codecov-commenter commented Dec 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (277b90f) 98.10% compared to head (5e1a480) 98.10%.

Additional details and impacted files
@@            Coverage Diff             @@
##              2.0    #3322      +/-   ##
==========================================
- Coverage   98.10%   98.10%   -0.01%     
==========================================
  Files        1252     1252              
  Lines       72342    72303      -39     
  Branches     3387     3387              
==========================================
- Hits        70974    70935      -39     
  Misses       1368     1368              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -48,7 +48,7 @@ def initialize(
# Dup and freeze strings so they aren't modified by reference.
@env = Core::Utils::SafeDup.frozen_dup(env || Datadog.configuration.env)
@service = Core::Utils::SafeDup.frozen_dup(service || Datadog.configuration.service)
@span_id = span_id || 0
@span_id = (span_id || 0).to_s
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TonyCTHsu I don't remember: why are we converting the numbers to strings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcotc's question suggests that we should include that in the release notes somewhere.

Apparently, Ruby integers can natively handle 128-bit numbers, so I agree. It's not clear why we need to convert them to strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcotc @ekump The value returned by those methods are meant to be injected into log entries.

Hence, returning string instead of integer provides finer control for implementing different encoding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value returned by those methods are meant to be injected into log entries

Is that the only supported use for the return value? This is part of the public API, so should we be considering more generic usage?

Generally speaking, I don't think public API methods should be too opinionated on what is done with their return values (within reason) and we should be returning values as the types that best reflect what they are. This contributes to an API being predictable and intuitive for an engineer to use. If I know trace_ids are 128-bit integers, and I see a method called trace_id I would assume/expect it to return an integer.

It should be the responsibility of the calling method to convert it to a string and/or encode it a particular way unless we have a good reason to do otherwise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekump we have the method #to_log_format which is a helper method you use when you want to inject the correlation into your logs safely, that method is opinionated.

Copy link
Member

@marcotc marcotc Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here an interesting bit, OTel uses 128-bit trace ids as well, but it represents them as 16-char strings.
OTel always passes these 16 bytes around or, if needed to be converted to a printable string, converts it to hex representation.

@@ -48,7 +48,7 @@ def initialize(
# Dup and freeze strings so they aren't modified by reference.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's document that "this class is for usage with log correlation. To continue from a trace, users should use TraceDigest instead."

@TonyCTHsu TonyCTHsu merged commit af8859f into 2.0 Jan 26, 2024
151 checks passed
@TonyCTHsu TonyCTHsu deleted the tonycthsu/correlation-string branch January 26, 2024 21:12
@TonyCTHsu TonyCTHsu added this to the 2.0 milestone Feb 20, 2024
@ivoanjo ivoanjo added the 2.0 label Mar 14, 2024
@TonyCTHsu TonyCTHsu modified the milestones: 2.0, 2.0.0.beta1 Mar 22, 2024
@TonyCTHsu TonyCTHsu mentioned this pull request Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 breaking-change Involves a breaking change tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants