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

fix: correlation context propagation extract for a single entry #1336

Merged
merged 4 commits into from
Aug 14, 2020

Conversation

rubenvp8510
Copy link
Contributor

@rubenvp8510 rubenvp8510 commented Jul 22, 2020

Signed-off-by: Ruben Vargas [email protected]

Which problem is this PR solving?

  • The extraction of the correlation context fails when only have one entry "key=value"

Short description of the changes

  • Fixes that case, and make sure it fails and return no correlation context if the header format is wrong.

@codecov
Copy link

codecov bot commented Jul 22, 2020

Codecov Report

Merging #1336 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           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           
Impacted Files Coverage Δ
...tion-context/propagation/HttpCorrelationContext.ts 98.03% <100.00%> (+0.03%) ⬆️

@@ -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++) {
Copy link
Member

@obecny obecny Jul 22, 2020

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);

Copy link
Contributor Author

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?

Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Member

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

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 skip malformed pairs and keep processing.

@rubenvp8510
Copy link
Contributor Author

Hi, I did the changes to skip only malformed keys, also modified the test of failures to include that case.

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, one comment

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

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

LGTM thanks

@dyladan dyladan added bug Something isn't working release:required-for-ga labels Jul 28, 2020
@dyladan dyladan merged commit 8224e1f into open-telemetry:master Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants