-
Notifications
You must be signed in to change notification settings - Fork 304
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
implement w3c phase 3 #4325
implement w3c phase 3 #4325
Conversation
Overall package sizeSelf size: 6.62 MB Dependency sizes
🤖 This report was automatically generated by heaviest-objects-in-the-universe |
3386657
to
c6143f3
Compare
BenchmarksBenchmark execution time: 2024-06-04 19:44:43 Comparing candidate commit eaeb59d in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 258 metrics, 8 unstable metrics. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4325 +/- ##
===========================================
+ Coverage 69.19% 93.09% +23.90%
===========================================
Files 1 97 +96
Lines 198 3028 +2830
Branches 33 33
===========================================
+ Hits 137 2819 +2682
- Misses 61 209 +148 ☔ View full report in Codecov by Sentry. |
The systems tests cover more scenarios and they have been tested locally and are all passing. These are the system tests tested against: https://github.com/DataDog/system-tests/blob/main/tests/parametric/test_headers_tracecontext.py#L717-%23L809 |
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.
left some nits. Overall looks really good
if (spanContext !== null) { | ||
return spanContext | ||
} | ||
|
||
return this._extractSqsdContext(carrier) |
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.
Can we simplify this to:
if (spanContext !== null) { | |
return spanContext | |
} | |
return this._extractSqsdContext(carrier) | |
return spanContext || this._extractSqsdContext(carrier) |
if (w3cCtx !== null && spanContext.toTraceId(true) === w3cCtx.toTraceId(true) && | ||
spanContext.toSpanId() !== w3cCtx.toSpanId()) { | ||
if ('_dd.parent_id' in w3cCtx._trace.tags && w3cCtx._trace.tags['_dd.parent_id'] !== | ||
'0000000000000000') { |
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.
Should we make 0000000000000000
and '_dd.parent_id' constants?
|
||
const w3cCtx = this._extractTraceparentContext(carrier) | ||
|
||
if (w3cCtx !== null && spanContext.toTraceId(true) === w3cCtx.toTraceId(true) && |
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.
Should we add a comment to document this behavior or encapsulate it in a method.
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.
Looks good from the API team perspective. Make sure you run the W3C system tests locally before merging the PR
@@ -214,9 +216,43 @@ class TextMapPropagator { | |||
return this._config.tracePropagationStyle[mode].includes(name) | |||
} | |||
|
|||
_ensureTraceContextTakePrecedence (traceContext, spanContext, carrier) { |
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.
nit: We can make these parameters a little more clear
_ensureTraceContextTakePrecedence (traceContext, spanContext, carrier) { | |
_ensureTraceContextTakePrecedence (w3cSpanContext, firstSpanContext, carrier) { |
if (extractor !== 'tracecontext') { | ||
continue | ||
} | ||
spanContext = this._ensureTraceContextTakePrecedence( |
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.
nit: Tracecontext only takes precedence if we detect a conflicting spans in the same trace. We should try to make that clear (with a common or in the function name).
spanContext = this._ensureTraceContextTakePrecedence( | |
spanContext = this._resolveTraceContextConflicts( |
@@ -214,9 +216,43 @@ class TextMapPropagator { | |||
return this._config.tracePropagationStyle[mode].includes(name) | |||
} | |||
|
|||
_resolveTraceContextConflicts (w3cSpanContext, firstSpanContext, carrier) { |
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 function would be a lot easier to read if split up with smaller functions with representative names that would also replace comments. For example hasTraceParent
etc.
@@ -523,6 +523,19 @@ describe('TextMapPropagator', () => { | |||
expect(spanContext._tracestate).to.be.undefined | |||
}) | |||
|
|||
it('extracts span_id from tracecontext headers and stores datadog parent-id in trace_distributed_tags', () => { |
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.
There was a lot of new code with many branches added. Should there be more tests for all combinations?
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.
All the branches should be tested by the following system tests: https://github.com/DataDog/system-tests/blob/main/tests/parametric/test_headers_tracecontext.py#L717-%23L809 (including the scenario in this unit test).
We are trying to avoid writing the same test cases in 8 different languages.
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 understand the goal, but with that approach, how can we know that things continue to work while working locally? And how do we monitor code coverage?
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.
Yup we can add one more test and test should give us full code coverage. We can use the system tests to address edges with unexpected inputs.
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.
Added a new unit test to address all branch's
17ffb42
to
d7f9b96
Compare
@@ -39,6 +39,8 @@ const tracestateTagKeyFilter = /[^\x21-\x2b\x2d-\x3c\x3e-\x7e]/g | |||
// Tag values in tracestate replace ',', '~' and ';' with '_' | |||
const tracestateTagValueFilter = /[^\x20-\x2b\x2d-\x3a\x3c-\x7d]/g | |||
const invalidSegment = /^0+$/ | |||
const ddParentIdTagKey = '_dd.parent_id' | |||
const zeroHex = '0000000000000000' |
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.
The variable name is a bit too literal IMO. For example, if I had a button with a warning color of "FF0000", which is red, the literal name would be const colorRed
but a more descriptive name would be const colorWarning
.
What is zeroHex really? Is it the trace ID of a parentless span? If so, a more descriptive name like "rootSpanTraceId" would be better. Otherwise using zeroHex
is no better than '0000000000000000'
in the code.
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 like zeroTraceId
for this.
@@ -39,6 +39,8 @@ const tracestateTagKeyFilter = /[^\x21-\x2b\x2d-\x3c\x3e-\x7e]/g | |||
// Tag values in tracestate replace ',', '~' and ';' with '_' | |||
const tracestateTagValueFilter = /[^\x20-\x2b\x2d-\x3a\x3c-\x7d]/g | |||
const invalidSegment = /^0+$/ | |||
const ddParentIdTagKey = '_dd.parent_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.
Nit: There's a tags.js file that lists common tag names. Should entries like these be listed in that file? /cc @bengl
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.
Yes it should. @khanayan123 can you please make that change?
@@ -39,6 +39,8 @@ const tracestateTagKeyFilter = /[^\x21-\x2b\x2d-\x3c\x3e-\x7e]/g | |||
// Tag values in tracestate replace ',', '~' and ';' with '_' | |||
const tracestateTagValueFilter = /[^\x20-\x2b\x2d-\x3a\x3c-\x7d]/g | |||
const invalidSegment = /^0+$/ | |||
const ddParentIdTagKey = '_dd.parent_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.
Yes it should. @khanayan123 can you please make that change?
@@ -39,6 +39,8 @@ const tracestateTagKeyFilter = /[^\x21-\x2b\x2d-\x3c\x3e-\x7e]/g | |||
// Tag values in tracestate replace ',', '~' and ';' with '_' | |||
const tracestateTagValueFilter = /[^\x20-\x2b\x2d-\x3a\x3c-\x7d]/g | |||
const invalidSegment = /^0+$/ | |||
const ddParentIdTagKey = '_dd.parent_id' | |||
const zeroHex = '0000000000000000' |
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 like zeroTraceId
for this.
7723d97
to
eaeb59d
Compare
What does this PR do?
ensure tracecontext headers take precedence over all distributed tracing header formats
Motivation
Implement W3C phase 3
Additional Notes
Tested against these set of system tests:
https://github.com/DataDog/system-tests/blob/main/tests/parametric/test_headers_tracecontext.py#L717-%23L809