-
Notifications
You must be signed in to change notification settings - Fork 821
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
feat: implement W3C Correlation Context propagator #838
Conversation
e82d1c9
to
768fd05
Compare
Codecov Report
@@ 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
|
packages/opentelemetry-core/src/distribute-context/propagation/HttpTraceContext.ts
Outdated
Show resolved
Hide resolved
const headerValue = Object.keys(distContext) | ||
.map( | ||
(key: string) => | ||
`${encodeURIComponent(key)}=${encodeURIComponent( |
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 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.
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, I'll d those limits.
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.
Should we throw an exception when the limits are exceeded? or skip the key-value pair? WDYT?
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.
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.
packages/opentelemetry-core/src/distribute-context/propagation/HttpTraceContext.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/src/distribute-context/propagation/HttpTraceContext.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/src/distribute-context/propagation/HttpTraceContext.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/src/distribute-context/distribute-context.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/src/distribute-context/propagation/HttpTraceContext.ts
Outdated
Show resolved
Hide resolved
61d6eba
to
8b570dc
Compare
Addressed all observations |
Any other observation on this ? |
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'; |
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 header should be otcorrelations
per the spec PR which was merged today. After this change this PR is mergeable. Sorry this took so long.
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.
Changed
Thanks for the review.
27e47fd
to
931ffaa
Compare
packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts
Outdated
Show resolved
Hide resolved
inject(context: Context, carrier: unknown, setter: SetterFunction) { | ||
const distContext = getCorrelationContext(context); | ||
if (distContext) { | ||
const all = Object.keys(distContext); |
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.
s/all/keys
?
packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts
Show resolved
Hide resolved
packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts
Outdated
Show resolved
Hide resolved
9839316
to
0ff1c15
Compare
Signed-off-by: Ruben Vargas <[email protected]> Signed-off-by: Ruben Vargas <[email protected]>
Signed-off-by: Ruben Vargas <[email protected]>
Signed-off-by: Ruben Vargas <[email protected]>
Signed-off-by: Ruben Vargas <[email protected]>
ac11b40
to
193b5f9
Compare
const correlationContext = getCorrelationContext(context); | ||
if (!correlationContext) return; | ||
const all = Object.keys(correlationContext); | ||
const values = all |
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.
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); |
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.
consider creating a helper function, maybe a parseHeader
or parsePair
etc. ?
}); | ||
}); | ||
|
||
it('returns null if header is missing', () => { |
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.
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) { |
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 think it is already safe to use repeat
here
value = '1a'.repeat(MAX_PER_NAME_VALUE_PAIRS_);
'OpenTelemetry Distributed Contexts Key' | ||
); | ||
|
||
export function getCorrelationContext( |
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.
missing tsdoc
); | ||
} | ||
|
||
export function setCorrelationContext( |
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.
missing tsdoc
|
||
/* W3C Constrains*/ | ||
|
||
export const MAX_NAME_VALUE_PAIRS = 180; |
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.
missing tsdoc
/* W3C Constrains*/ | ||
|
||
export const MAX_NAME_VALUE_PAIRS = 180; | ||
export const MAX_PER_NAME_VALUE_PAIRS = 4096; |
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.
missing tsdoc
|
||
export const MAX_NAME_VALUE_PAIRS = 180; | ||
export const MAX_PER_NAME_VALUE_PAIRS = 4096; | ||
export const MAX_TOTAL_LENGTH = 8192; |
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.
missing tsdoc
setCorrelationContext, | ||
} from '../correlation-context'; | ||
|
||
export const CORRELATION_CONTEXT_HEADER = 'otcorrelations'; |
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.
missing tsdoc
packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts
Show resolved
Hide resolved
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.
Added one comment, overall LGTM.
Signed-off-by: Ruben Vargas <[email protected]>
Done with all comments. |
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, thx for those changes
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). |
Which problem is this PR solving?
Short description of the changes