-
Notifications
You must be signed in to change notification settings - Fork 805
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
Pass W3C Trace Context test suite at strictness 1 #1406
Pass W3C Trace Context test suite at strictness 1 #1406
Conversation
@@ -27,8 +27,14 @@ import { getParentSpanContext, setExtractedSpanContext } from '../context'; | |||
|
|||
export const TRACE_PARENT_HEADER = 'traceparent'; | |||
export const TRACE_STATE_HEADER = 'tracestate'; | |||
const VALID_TRACE_PARENT_REGEX = /^(?!ff)[\da-f]{2}-([\da-f]{32})-([\da-f]{16})-([\da-f]{2})(-|$)/; |
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.
While a single regex can be nice aesthetically, it became kinda awkward here trying to support current (strict) version requirements and future (less-strict) requirements.
Could have handled by also capturing the version and doing a later comparison of version + parsed final match part (-|$)
but that seemed less straightforward and likely to need overhaul in future versions. I'm hoping the different parts makes any potential future version require less restructuring.
if ( | ||
!match || | ||
match[1] === '00000000000000000000000000000000' || |
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.
These validations moved into the respective regex validators.
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.
+1
@@ -41,19 +47,33 @@ const VERSION = '00'; | |||
* For more information see {@link https://www.w3.org/TR/trace-context/} | |||
*/ | |||
export function parseTraceParent(traceParent: string): SpanContext | null { | |||
const match = traceParent.match(VALID_TRACE_PARENT_REGEX); | |||
const trimmed = traceParent.trim(); |
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.
Arguable if we need this. Don't believe there's anything in the spec saying we need to support such but also seems nice to have.
That being said, it does add an additional string creation.
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.
Isn't it superfluous? I don't think this is being done in other languages. Would be nice to know the reasoning behind this.
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.
Basically, there's a chance you could have a trailing whitespace character (OWS) in the traceparent and this removes that, so as not to lump it into the flags validation. It is just a potential nice to have.
It does look like trailing whitespace values are removed as of Node 10.19.0, 12.15.0 and 13.8.0 for security reasons (all released on 02/06/2020), so it will be wasted effort as of those versions. I'm assuming we'll drop Node 8 support at some point to match Node itself, but that will continue to have issues.
Happy to remove in this PR, or a follow-up, if we don't want that code in there.
@@ -68,10 +68,11 @@ export class TraceState implements api.TraceState { | |||
.split(LIST_MEMBERS_SEPARATOR) | |||
.reverse() // Store in reverse so new keys (.set(...)) will be placed at the beginning | |||
.reduce((agg: Map<string, string>, part: string) => { | |||
const i = part.indexOf(LIST_MEMBER_KEY_VALUE_SPLITTER); | |||
const listMember = part.trim(); // Optional Whitespace (OWS) handling |
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 adds the OWS support / fixes those related errors. While it does add an additional string, there's likely other more impactful optimizations we could do in this area if it became a concern.
it('should handle OWS in tracestate list members', () => { | ||
carrier[TRACE_PARENT_HEADER] = | ||
'00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01'; | ||
carrier[TRACE_STATE_HEADER] = 'foo=1 \t , \t bar=2, \t baz=3 '; |
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 a reasonable subset of what we were failing on.
Codecov Report
@@ Coverage Diff @@
## master #1406 +/- ##
==========================================
+ Coverage 94.13% 94.15% +0.01%
==========================================
Files 145 145
Lines 4314 4326 +12
Branches 877 881 +4
==========================================
+ Hits 4061 4073 +12
Misses 253 253
|
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.
LGTM thanks for taking this on
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.
LGTM. Thanks @michaelgoin!
@open-telemetry/javascript-approvers looking for a couple more approvals here. Now that we've merged the test suite, the build is failing every time until this is merged. |
Which problem is this PR solving?
This fixes
STRICT_LEVEL=1
failures surfaced by the test server PR: #1380.No longer allows extra parts for version 00 of trace parent.
This is one of those implicit requirements that is not clearly stated out in the spec. Extra parts should only be allowed for future versions (grabbing what we support) but version 00 only has the 4 parts.
Tracestate Header list members now handle/strip optional whitespace (OWS).
W3C Trace Context spec: https://www.w3.org/TR/trace-context/
Validation test repo: https://github.com/w3c/trace-context/tree/master/test
Short description of the changes
Prior to fix
After Fix