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

feat: implement W3C Correlation Context propagator #838

Merged

Conversation

rubenvp8510
Copy link
Contributor

Which problem is this PR solving?

Short description of the changes

  • This PR implements propagation for correlation context

@rubenvp8510 rubenvp8510 force-pushed the dist-context-propagation branch 3 times, most recently from e82d1c9 to 768fd05 Compare March 3, 2020 21:43
@codecov-io
Copy link

codecov-io commented Mar 3, 2020

Codecov Report

Merging #838 into master will increase coverage by 0.04%.
The diff coverage is 99.09%.

@@            Coverage Diff             @@
##           master     #838      +/-   ##
==========================================
+ Coverage   95.12%   95.17%   +0.04%     
==========================================
  Files         213      216       +3     
  Lines        8952     9063     +111     
  Branches      806      819      +13     
==========================================
+ Hits         8516     8626     +110     
- Misses        436      437       +1     
Impacted Files Coverage Δ
...tion-context/propagation/HttpCorrelationContext.ts 98.00% <98.00%> (ø)
...ore/src/correlation-context/correlation-context.ts 100.00% <100.00%> (ø)
...correlation-context/HttpCorrelationContext.test.ts 100.00% <100.00%> (ø)

const headerValue = Object.keys(distContext)
.map(
(key: string) =>
`${encodeURIComponent(key)}=${encodeURIComponent(
Copy link
Member

Choose a reason for hiding this comment

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

I think we should consider below limits as per the specs: https://w3c.github.io/correlation-context/#header-value

Limits:

  • Maximum number of name-value pairs: 180.
  • Maximum number of bytes per a single name-value pair: 4096.
  • Maximum total length of all name-value pairs: 8192.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1, I'll d those limits.

Copy link
Contributor Author

@rubenvp8510 rubenvp8510 Mar 25, 2020

Choose a reason for hiding this comment

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

Should we throw an exception when the limits are exceeded? or skip the key-value pair? WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

In general we never throw if we can avoid it. I would suggest to log and skip WDYT @mayurkale22

This may be a question for spec as well.

@dyladan dyladan mentioned this pull request Mar 4, 2020
46 tasks
@rubenvp8510 rubenvp8510 force-pushed the dist-context-propagation branch 2 times, most recently from 61d6eba to 8b570dc Compare March 26, 2020 04:49
@rubenvp8510
Copy link
Contributor Author

Addressed all observations

@rubenvp8510
Copy link
Contributor Author

Any other observation on this ?

@dyladan
Copy link
Member

dyladan commented Apr 13, 2020

I am waiting for the spec issue to be resolved before merging this. The spec header name has had some back and forth.

setCorrelationContext,
} from '../correlation-context';

export const CORRELATION_CONTEXT_HEADER = 'otcorrelationcontext';
Copy link
Member

Choose a reason for hiding this comment

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

This header should be otcorrelations per the spec PR which was merged today. After this change this PR is mergeable. Sorry this took so long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

Thanks for the review.

@rubenvp8510 rubenvp8510 force-pushed the dist-context-propagation branch 3 times, most recently from 27e47fd to 931ffaa Compare May 15, 2020 15:50
inject(context: Context, carrier: unknown, setter: SetterFunction) {
const distContext = getCorrelationContext(context);
if (distContext) {
const all = Object.keys(distContext);
Copy link
Member

Choose a reason for hiding this comment

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

s/all/keys?

@mayurkale22 mayurkale22 added the enhancement New feature or request label May 15, 2020
@mayurkale22 mayurkale22 added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 15, 2020
@rubenvp8510 rubenvp8510 force-pushed the dist-context-propagation branch 2 times, most recently from 9839316 to 0ff1c15 Compare May 18, 2020 02:25
@rubenvp8510 rubenvp8510 force-pushed the dist-context-propagation branch from ac11b40 to 193b5f9 Compare May 18, 2020 03:41
const correlationContext = getCorrelationContext(context);
if (!correlationContext) return;
const all = Object.keys(correlationContext);
const values = all
Copy link
Member

Choose a reason for hiding this comment

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

Please make an util helper function from this, and the same for values.reduce, it is hard to understand what is happening here, without looking and analysing the code

const pairs = headerValue.split(ITEMS_SEPARATOR);
if (pairs.length == 1) return context;
pairs.forEach(entry => {
const valueProps = entry.split(PROPERTIES_SEPARATOR);
Copy link
Member

Choose a reason for hiding this comment

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

consider creating a helper function, maybe a parseHeader or parsePair etc. ?

});
});

it('returns null if header is missing', () => {
Copy link
Member

Choose a reason for hiding this comment

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

it says null, but is being compared against undefined


let value = '';
// Generate long value 2*MAX_PER_NAME_VALUE_PAIRS
for (let i = 0; i < MAX_PER_NAME_VALUE_PAIRS; ++i) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it is already safe to use repeat here

value = '1a'.repeat(MAX_PER_NAME_VALUE_PAIRS_);

'OpenTelemetry Distributed Contexts Key'
);

export function getCorrelationContext(
Copy link
Member

Choose a reason for hiding this comment

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

missing tsdoc

);
}

export function setCorrelationContext(
Copy link
Member

Choose a reason for hiding this comment

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

missing tsdoc


/* W3C Constrains*/

export const MAX_NAME_VALUE_PAIRS = 180;
Copy link
Member

Choose a reason for hiding this comment

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

missing tsdoc

/* W3C Constrains*/

export const MAX_NAME_VALUE_PAIRS = 180;
export const MAX_PER_NAME_VALUE_PAIRS = 4096;
Copy link
Member

Choose a reason for hiding this comment

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

missing tsdoc


export const MAX_NAME_VALUE_PAIRS = 180;
export const MAX_PER_NAME_VALUE_PAIRS = 4096;
export const MAX_TOTAL_LENGTH = 8192;
Copy link
Member

Choose a reason for hiding this comment

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

missing tsdoc

setCorrelationContext,
} from '../correlation-context';

export const CORRELATION_CONTEXT_HEADER = 'otcorrelations';
Copy link
Member

Choose a reason for hiding this comment

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

missing tsdoc

Copy link
Member

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

Added one comment, overall LGTM.

@rubenvp8510
Copy link
Contributor Author

Done with all comments.

@mayurkale22 mayurkale22 requested a review from obecny May 18, 2020 19:28
Copy link
Member

@obecny obecny left a comment

Choose a reason for hiding this comment

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

lgtm, thx for those changes

@mayurkale22
Copy link
Member

It would be nice if you can add this into Built-in Propagators (in a separate PR) doc (See: https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-core#built-in-propagators).

@mayurkale22 mayurkale22 merged commit f978377 into open-telemetry:master May 19, 2020
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement W3C Correlation Context propagator
7 participants