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

implement w3c phase 3 #4325

Merged
merged 8 commits into from
Jun 4, 2024
Merged

implement w3c phase 3 #4325

merged 8 commits into from
Jun 4, 2024

Conversation

khanayan123
Copy link
Collaborator

@khanayan123 khanayan123 commented May 17, 2024

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

@khanayan123 khanayan123 requested a review from mabdinur May 17, 2024 20:02
Copy link

github-actions bot commented May 17, 2024

Overall package size

Self size: 6.62 MB
Deduped: 61.87 MB
No deduping: 62.15 MB

Dependency sizes

name version self size total size
@datadog/native-appsec 8.0.1 15.59 MB 15.6 MB
@datadog/native-iast-taint-tracking 2.1.0 14.91 MB 14.92 MB
@datadog/pprof 5.3.0 9.85 MB 10.22 MB
protobufjs 7.2.5 2.77 MB 6.56 MB
@datadog/native-iast-rewriter 2.3.1 2.15 MB 2.24 MB
@opentelemetry/core 1.14.0 872.87 kB 1.47 MB
@datadog/native-metrics 2.0.0 898.77 kB 1.3 MB
@opentelemetry/api 1.8.0 1.21 MB 1.21 MB
import-in-the-middle 1.7.4 70.19 kB 739.86 kB
msgpack-lite 0.1.26 201.16 kB 281.59 kB
opentracing 0.14.7 194.81 kB 194.81 kB
semver 7.5.4 93.4 kB 123.8 kB
pprof-format 2.1.0 111.69 kB 111.69 kB
@datadog/sketches-js 2.1.0 109.9 kB 109.9 kB
lodash.sortby 4.7.0 75.76 kB 75.76 kB
lru-cache 7.14.0 74.95 kB 74.95 kB
ignore 5.2.4 51.22 kB 51.22 kB
int64-buffer 0.1.10 49.18 kB 49.18 kB
shell-quote 1.8.1 44.96 kB 44.96 kB
istanbul-lib-coverage 3.2.0 29.34 kB 29.34 kB
tlhunter-sorted-set 0.1.0 24.94 kB 24.94 kB
limiter 1.1.5 23.17 kB 23.17 kB
dc-polyfill 0.1.4 23.1 kB 23.1 kB
retry 0.13.1 18.85 kB 18.85 kB
jest-docblock 29.7.0 8.99 kB 12.76 kB
crypto-randomuuid 1.0.0 11.18 kB 11.18 kB
path-to-regexp 0.1.7 6.78 kB 6.78 kB
koalas 1.0.2 6.47 kB 6.47 kB
module-details-from-path 1.0.3 4.47 kB 4.47 kB

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@khanayan123 khanayan123 changed the title implent w3c phase 3 implement w3c phase 3 May 17, 2024
@khanayan123 khanayan123 force-pushed the khanayan123/implement-w3c-phase3 branch from 3386657 to c6143f3 Compare May 17, 2024 20:05
@pr-commenter
Copy link

pr-commenter bot commented May 17, 2024

Benchmarks

Benchmark execution time: 2024-06-04 19:44:43

Comparing candidate commit eaeb59d in PR branch khanayan123/implement-w3c-phase3 with baseline commit 0e1f0cf in branch master.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 258 metrics, 8 unstable metrics.

Copy link

codecov bot commented May 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.09%. Comparing base (e60feae) to head (dea3ddf).
Report is 3 commits behind head on master.

Current head dea3ddf differs from pull request most recent head eaeb59d

Please upload reports for the commit eaeb59d to get more accurate results.

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.
📢 Have feedback on the report? Share it here.

@khanayan123
Copy link
Collaborator Author

khanayan123 commented May 17, 2024

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

Copy link
Contributor

@mabdinur mabdinur left a 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

Comment on lines 270 to 274
if (spanContext !== null) {
return spanContext
}

return this._extractSqsdContext(carrier)
Copy link
Contributor

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:

Suggested change
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') {
Copy link
Contributor

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) &&
Copy link
Contributor

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.

@khanayan123 khanayan123 requested a review from mabdinur May 20, 2024 17:04
Copy link
Contributor

@mabdinur mabdinur left a 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) {
Copy link
Contributor

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

Suggested change
_ensureTraceContextTakePrecedence (traceContext, spanContext, carrier) {
_ensureTraceContextTakePrecedence (w3cSpanContext, firstSpanContext, carrier) {

if (extractor !== 'tracecontext') {
continue
}
spanContext = this._ensureTraceContextTakePrecedence(
Copy link
Contributor

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

Suggested change
spanContext = this._ensureTraceContextTakePrecedence(
spanContext = this._resolveTraceContextConflicts(

@khanayan123 khanayan123 requested a review from mabdinur May 20, 2024 17:44
@@ -214,9 +216,43 @@ class TextMapPropagator {
return this._config.tracePropagationStyle[mode].includes(name)
}

_resolveTraceContextConflicts (w3cSpanContext, firstSpanContext, carrier) {
Copy link
Member

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', () => {
Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Collaborator Author

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

mabdinur
mabdinur previously approved these changes May 24, 2024
@khanayan123 khanayan123 force-pushed the khanayan123/implement-w3c-phase3 branch 2 times, most recently from 17ffb42 to d7f9b96 Compare June 3, 2024 22:42
@khanayan123 khanayan123 marked this pull request as ready for review June 4, 2024 14:59
@khanayan123 khanayan123 requested a review from a team as a code owner June 4, 2024 14:59
@@ -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'
Copy link
Member

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.

Copy link
Collaborator

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'
Copy link
Member

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

Copy link
Collaborator

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?

bengl
bengl previously approved these changes Jun 4, 2024
@@ -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'
Copy link
Collaborator

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'
Copy link
Collaborator

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.

@khanayan123 khanayan123 force-pushed the khanayan123/implement-w3c-phase3 branch from 7723d97 to eaeb59d Compare June 4, 2024 19:34
@khanayan123 khanayan123 merged commit 7b2dee1 into master Jun 4, 2024
133 checks passed
@khanayan123 khanayan123 deleted the khanayan123/implement-w3c-phase3 branch June 4, 2024 19:52
juan-fernandez pushed a commit that referenced this pull request Jun 5, 2024
* implent w3c phase 3
juan-fernandez pushed a commit that referenced this pull request Jun 5, 2024
* implent w3c phase 3
juan-fernandez pushed a commit that referenced this pull request Jun 5, 2024
* implent w3c phase 3
juan-fernandez pushed a commit that referenced this pull request Jun 5, 2024
* implent w3c phase 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants