Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

HTTP Propagation: set Correlation-Context header #567

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mayurkale22
Copy link
Member

@codecov-io
Copy link

codecov-io commented May 30, 2019

Codecov Report

Merging #567 into master will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/stackdriver-monitoring.ts 77.02% <0%> (-2.71%) ⬇️
src/http.ts 90.3% <0%> (-0.06%) ⬇️
src/binary-format.ts 100% <0%> (ø) ⬆️
test/test-http.ts 98.86% <0%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 039c695...958c9e3. Read the comment docs.

@mayurkale22 mayurkale22 requested a review from songy23 May 31, 2019 03:55
packages/opencensus-instrumentation-http/src/http.ts Outdated Show resolved Hide resolved
* retrieved.
*/
static getTagContext(headers: IncomingHttpHeaders): TagMap|null {
const contextValue = (headers[CORRELATION_CONTEXT.toLocaleLowerCase()] ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why toLocaleLowerCase?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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

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.

* retrieved.
*/
static getTagContext(headers: IncomingHttpHeaders): TagMap|null {
const contextValue = (headers[CORRELATION_CONTEXT.toLocaleLowerCase()] ||
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tags: Support HTTP propagation.
5 participants