-
Notifications
You must be signed in to change notification settings - Fork 96
HTTP Propagation: set Correlation-Context
header
#567
base: master
Are you sure you want to change the base?
HTTP Propagation: set Correlation-Context
header
#567
Conversation
Codecov Report
@@ Coverage Diff @@
## master #567 +/- ##
=========================================
+ Coverage 95.3% 95.3% +<.01%
=========================================
Files 148 148
Lines 10590 10656 +66
Branches 746 749 +3
=========================================
+ Hits 10093 10156 +63
- Misses 497 500 +3
Continue to review full report at Codecov.
|
* retrieved. | ||
*/ | ||
static getTagContext(headers: IncomingHttpHeaders): TagMap|null { | ||
const contextValue = (headers[CORRELATION_CONTEXT.toLocaleLowerCase()] || |
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.
Why toLocaleLowerCase
?
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.
AFAIK Node core automatically converts all HTTP headers to lowercase. Without much frills, I easily found the location where outgoing HTTP headers are converted to lowercase.
@draffensperger correct me if this statement is wrong.
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.
What would you think about just making the constant itself be in lower case so you don't need to convert it here along with a comment that Node converts headers to lower case?
I'm not super familiar with how headers in Node are handled. Could this be related? nodejs/node-v0.x-archive#1954
How are headers for trace context handled? Do we assume those are lowercase?
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.
TraceContext headers are defined in lower case only. As per official documentation -> In order to increase interoperability across multiple protocols and encourage successful integration by default it is recommended to keep the header name lower case. Platforms and libraries MUST expect header name in any casing and SHOULD send header name in lower case.
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.
OK, I guess I'm a little confused by the code then, to me it looks like you are looking for the header key in lower case rather than converting all the incoming headers to lower case to compare them?
Or am I missing something 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.
TraceContext headers are defined in lower case only.
That's for TraceContext
. I don't think it's the case for Correlation-Context
, per https://github.com/w3c/correlation-context/blob/master/correlation_context/HTTP_HEADER_FORMAT.md#examples-of-http-headers.
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.
Phrased a different way, how do you know that headers: IncomingHttpHeaders
here will always have its values in lower case? Could they ever be in upper-case, and if so, should you just convert them to lower case to make sure before comparing them to a lower-cased header?
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.
how do you know that headers: IncomingHttpHeaders here will always have its values in lower case? Could they ever be in upper-case?
Not 100% sure on this, perhaps that's why we use both the variant of user-agent
key. I think it is safe bet to compare both the variant until we don;t know the complete picture.
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.
Makes sense. Maybe you can just making both the incoming header and the constant be lower case and compare those?
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'm going to approve this, and if this comes up as a bug in the future, it should be fixed.
@@ -290,6 +303,60 @@ describe('HttpPlugin', () => { | |||
}); | |||
}); | |||
|
|||
it('should create a child span for GET requests with tag context', () => { |
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'm not sure if I understand these tests - why test spans? Same for other tests.
f19c2b4
to
958c9e3
Compare
958c9e3
to
4bf8ba1
Compare
* retrieved. | ||
*/ | ||
static getTagContext(headers: IncomingHttpHeaders): TagMap|null { | ||
const contextValue = (headers[CORRELATION_CONTEXT.toLocaleLowerCase()] || |
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'm going to approve this, and if this comes up as a bug in the future, it should be fixed.
Continuation of #445 and Fixes #297
Specs: https://github.com/census-instrumentation/opencensus-specs/blob/master/tags/TagMap.md#over-http