-
Notifications
You must be signed in to change notification settings - Fork 804
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
fix: correlation context propagation extract for a single entry #1336
fix: correlation context propagation extract for a single entry #1336
Conversation
020011d
to
4d3b06b
Compare
Codecov Report
@@ Coverage Diff @@
## master #1336 +/- ##
=======================================
Coverage 94.11% 94.11%
=======================================
Files 145 145
Lines 4334 4335 +1
Branches 883 883
=======================================
+ Hits 4079 4080 +1
Misses 255 255
|
packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts
Outdated
Show resolved
Hide resolved
4d3b06b
to
0b10969
Compare
@@ -91,13 +91,16 @@ export class HttpCorrelationContext implements HttpTextPropagator { | |||
return context; | |||
} | |||
const pairs = headerValue.split(ITEMS_SEPARATOR); | |||
if (pairs.length == 1) return context; | |||
pairs.forEach(entry => { | |||
for (let i = 0; i < pairs.length; 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.
this loops checks only a first pair, so either the loop is not needed, or you should check all pairs and if none of them matched then you should return context .
Hmm, something else is wrong here too or I don't get it.
What if the pair in the middle doesn't match and the rest pairs match ? Should it continue or it should return the context even though the previous pairs were added to the correlationContext.
shouldn't this look like this
let found = false;
pairs.forEach(entry => {
const keyPair = this._parsePairKeyValue(entry);
if (keyPair) {
found = true;
correlationContext[keyPair.key] = { value: keyPair.value };
}
})
if (!found) {
return context;
}
return setCorrelationContext(context, correlationContext);
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.
That is a good question, as it is now if there is an error in the header it returns the context without correlationContext, as you can see in this test: https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts#L154 , but may be we would like change this and continue parsing the other keys and return the well formed keys 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.
hmm so if I understand correctly only the line if (pairs.length == 1) return context;
should be removed and the rest stays as it was ?
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.
If we want to have a correlation context and only exclude malformed keys , I would say yes, and of change the tests here: https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-core/test/correlation-context/HttpCorrelationContext.test.ts#L154 to reflect that fact.
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 would like to hear here someone else opinion on that too, if that is the way to go?, @open-telemetry/javascript-approvers
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 skip malformed pairs and keep processing.
0b10969
to
986f631
Compare
Hi, I did the changes to skip only malformed keys, also modified the test of failures to include that 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.
lgtm, one comment
packages/opentelemetry-core/src/correlation-context/propagation/HttpCorrelationContext.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
986f631
to
d80a821
Compare
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
Signed-off-by: Ruben Vargas ruben.vp8510@gmail.com
Which problem is this PR solving?
Short description of the changes