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: redis instrumentation loses context when using callbacks #580

Merged

Conversation

aspectom
Copy link
Contributor

Which problem is this PR solving?

  • When using redis instrumentation with callbacks instead of async await, original span context is lost.

Short description of the changes

  • Call context.with when calling original callback

@aspectom aspectom marked this pull request as ready for review July 19, 2021 15:06
@aspectom aspectom requested a review from a team as a code owner July 19, 2021 15:06
Comment on lines 151 to 153
return context.with(originalContext, () => {
return originalCallback.apply(callbackThis, arguments);
});
Copy link
Member

Choose a reason for hiding this comment

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

You can also just do return context.with(originalContext, originalCallback, callbackThis, ...arguments) https://open-telemetry.github.io/opentelemetry-js-api/classes/contextapi.html#with

Copy link
Member

Choose a reason for hiding this comment

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

This way you avoid creating an additional function call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't aware of that one. thanks @dyladan , fixed :)

@codecov
Copy link

codecov bot commented Jul 19, 2021

Codecov Report

Merging #580 (f4b627b) into main (a63b828) will increase coverage by 0.00%.
The diff coverage is n/a.

❗ Current head f4b627b differs from pull request most recent head 52e90d9. Consider uploading reports for the commit 52e90d9 to get more accurate results

@@           Coverage Diff           @@
##             main     #580   +/-   ##
=======================================
  Coverage   94.94%   94.94%           
=======================================
  Files         195      195           
  Lines       11630    11637    +7     
  Branches     1115     1115           
=======================================
+ Hits        11042    11049    +7     
  Misses        588      588           
Impacted Files Coverage Δ
...e/opentelemetry-instrumentation-redis/src/utils.ts 92.98% <0.00%> (+0.12%) ⬆️
...telemetry-instrumentation-redis/test/redis.test.ts 95.65% <0.00%> (+0.14%) ⬆️

@vmarchaud vmarchaud requested a review from dyladan July 20, 2021 12:39
@dyladan dyladan added the bug Something isn't working label Jul 28, 2021
@obecny obecny merged commit f9bc4a1 into open-telemetry:main Aug 5, 2021
@dyladan dyladan mentioned this pull request Feb 28, 2022
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.

None yet

8 participants