-
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
set 128-bit trace_id to true by default #3266
Conversation
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.
Generally fine!
@@ -103,6 +109,8 @@ | |||
end | |||
|
|||
context 'nil' do | |||
include_context 'with 128-bit trace_id generation disabled' |
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 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'
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 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
.
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 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 |
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.
Is there any reason for this change?
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.
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.
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.
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?
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.
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
.
a6f4814
to
4f65aba
Compare
spec/datadog/opentelemetry_spec.rb
Outdated
'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, |
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.
@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.
spec/datadog/opentelemetry_spec.rb
Outdated
@@ -339,18 +339,21 @@ | |||
describe '#inject' do | |||
subject(:inject) { ::OpenTelemetry.propagation.inject(carrier) } | |||
let(:carrier) { {} } | |||
|
|||
let(:headers) do |
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.
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
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.
Good callout, updated the test.
b1884ac
to
3a617f1
Compare
3a617f1
to
95b2d08
Compare
95b2d08
to
45e2cc9
Compare
@@ -185,7 +195,7 @@ | |||
end | |||
|
|||
context 'with invalid tags' do | |||
let(:tags) { 'not_a_tag_hash' } | |||
let(:tags) { { 'key with=spaces' => 'value' } } |
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.
👍
# 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 |
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 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 ReportAll modified and coverable lines are covered by tests ✅
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. |
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:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance
.Unsure? Have a question? Request a review!