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

set 128-bit trace_id to true by default #3266

Merged
merged 4 commits into from
Nov 21, 2023
Merged

Conversation

ekump
Copy link
Contributor

@ekump ekump commented Nov 20, 2023

What does this PR do?
Changes the default configuration for 128-bit trace_id generation to true.

Motivation:
Part of Datadog's migration to W3C/128-bit tracers for OTEL compatibility.

Additional Notes:
When using 128-bit IDs internally, we propagate the 64-bit version in x-datadog-tags, which we do not do for 64-bit IDs. Some unit tests had to be updated to reflect this.

How to test the change?
Since this changes default behavior you just have to use the tracer with default settings to see the change.

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!

@ekump ekump requested review from a team as code owners November 20, 2023 19:35
@ekump ekump marked this pull request as draft November 20, 2023 19:38
Copy link
Contributor

@TonyCTHsu TonyCTHsu left a comment

Choose a reason for hiding this comment

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

Generally fine!

@@ -103,6 +109,8 @@
end

context 'nil' do
include_context 'with 128-bit trace_id generation disabled'
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer making examples more explicit by repeating

before do
  Datadog.configure { |c| c.tracing.trace_id_128_bit_generation_enabled = false }
end

Instead of adding an indirection

include_context 'with 128-bit trace_id generation disabled'

Copy link
Member

Choose a reason for hiding this comment

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

I agree here, given c.tracing.trace_id_128_bit_generation_enabled = false reads pretty much the same as with 128-bit trace_id generation disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree. I think the shared_context is a bit clearer in communicating intentions with the tests as well as removes some clutter. But since the actual context is so small I don't think it's the end of the world to revert this.

@@ -46,11 +46,18 @@ def inject!(digest, data)
data[@sampling_priority_key] = digest.trace_sampling_priority.to_s if digest.trace_sampling_priority
data[@origin_key] = digest.trace_origin.to_s if digest.trace_origin

build_tags(digest).tap do |tags|
inject_tags!(tags, data) unless tags.empty?
begin
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When using 128-bit ids, if the tags are invalid because they aren't a hash it will generate an exception when we attempt to merge them here.

It's possible to have an encoding error at either the build_tags or the inject_tags! steps, so I moved the rescue up to here.

Copy link
Contributor

@TonyCTHsu TonyCTHsu Nov 21, 2023

Choose a reason for hiding this comment

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

Interesting, I was not expecting build_tags would failed. Perhaps bad data from arbitrary digest?

I don't mind this changes that push the rescue logic higher up, but I think it slightly changing the contract of this method. Although inject! suggests this method contains side effect, the original method returns data explicitly(with or without exception). The changes with else statement alter the return value when there is an exception thrown.

Perhaps just return data in the last line explicitly without the else statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Closing the loop on this: Spoke with Tony and we decided to revert this and update the test instead. The likelihood of tags not being a hash is extremely unlikely, so we shouldn't be generating any exceptions in build_tags.

@TonyCTHsu TonyCTHsu added this to the 1.17.0 milestone Nov 20, 2023
@ekump ekump force-pushed the ekump/128-bit-ids-by-default branch 2 times, most recently from a6f4814 to 4f65aba Compare November 21, 2023 01:47
@ekump ekump marked this pull request as ready for review November 21, 2023 02:00
'x-datadog-sampling-priority' => '1',
'x-datadog-tags' => '_dd.p.dm=-0,_dd.p.tid=' +
Datadog::Tracing::Utils::TraceId.to_high_order(Datadog::Tracing.active_trace.id).to_s(16),
'x-datadog-trace-id' => Datadog::Tracing::Utils::TraceId.to_low_order(Datadog::Tracing.active_trace.id).to_s,
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 I added a helper for this but it's scoped to Tracing::Contrib so I can't / shouldn't use it outside of that.

@@ -339,18 +339,21 @@
describe '#inject' do
subject(:inject) { ::OpenTelemetry.propagation.inject(carrier) }
let(:carrier) { {} }

let(:headers) do
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine, but as a reminder. let would cache the result when first invoked, this could potentially cause stale values within a test life cycle if not paying attention, especially the data depends on a variable Datadog::Tracing.active_trace that changes with context.

I recommend

def headers
  {
    ...
  }
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good callout, updated the test.

@ekump ekump force-pushed the ekump/128-bit-ids-by-default branch from b1884ac to 3a617f1 Compare November 21, 2023 18:08
@ekump ekump force-pushed the ekump/128-bit-ids-by-default branch from 3a617f1 to 95b2d08 Compare November 21, 2023 18:22
@ekump ekump force-pushed the ekump/128-bit-ids-by-default branch from 95b2d08 to 45e2cc9 Compare November 21, 2023 18:36
@@ -185,7 +195,7 @@
end

context 'with invalid tags' do
let(:tags) { 'not_a_tag_hash' }
let(:tags) { { 'key with=spaces' => 'value' } }
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines 140 to 149
# Wraps call to Tracing::Utils::TraceId.to_low_order for better test readability
def low_order_trace_id(trace_id)
Datadog::Tracing::Utils::TraceId.to_low_order(trace_id)
end

# Wraps call to Tracing::Utils::TraceId.to_high_order and converts to hex
# for better test readability
def high_order_hex_trace_id(trace_id)
Datadog::Tracing::Utils::TraceId.to_high_order(trace_id).to_s(16)
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 these helpers are related to tracing, and not specifically contrib, as the 128-bit trace id generation is a part of core tracing.

I suggest moving these helpers to https://github.com/DataDog/dd-trace-rb/blob/master/spec/support/tracer_helpers.rb instead.

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1cba6bc) 98.22% compared to head (139e795) 98.22%.
Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3266   +/-   ##
=======================================
  Coverage   98.22%   98.22%           
=======================================
  Files        1253     1253           
  Lines       72198    72290   +92     
  Branches     3350     3361   +11     
=======================================
+ Hits        70916    71010   +94     
+ Misses       1282     1280    -2     

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

@ekump ekump merged commit 3becb40 into master Nov 21, 2023
218 checks passed
@ekump ekump deleted the ekump/128-bit-ids-by-default branch November 21, 2023 22:32
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.

5 participants