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: allow multiple instances of core to interact with context #1387

Merged

Conversation

dyladan
Copy link
Member

@dyladan dyladan commented Aug 4, 2020

Because of the way node handles modules, multiple instances of core may exist in the same installation. For instance, core may be depended on by a propagator, a plugin, and the tracing module. If any of these depend on a slightly different version, the functions used to interact with context will fail to work together. Using Symbol.for ensures these symbols are the same regardless of the instance of core that is being used.

@dyladan
Copy link
Member Author

dyladan commented Aug 4, 2020

Fixes #1379

@codecov
Copy link

codecov bot commented Aug 4, 2020

Codecov Report

Merging #1387 into master will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1387   +/-   ##
=======================================
  Coverage   94.03%   94.03%           
=======================================
  Files         149      149           
  Lines        4322     4322           
  Branches      880      880           
=======================================
  Hits         4064     4064           
  Misses        258      258           
Impacted Files Coverage Δ
packages/opentelemetry-context-base/src/context.ts 77.77% <100.00%> (ø)

@naseemkullah
Copy link
Member

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for

In contrast to Symbol(), the Symbol.for() function creates a symbol available in a global symbol registry list. Symbol.for() does also not necessarily create a new symbol on every call, but checks first if a symbol with the given key is already present in the registry. In that case, that symbol is returned. If no symbol with the given key is found, Symbol.for() will create a new global symbol.

@dyladan dyladan merged commit d4d6e1d into open-telemetry:master Aug 10, 2020
@dyladan dyladan deleted the symbol-for-context branch August 10, 2020 16:45
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 2022
dyladan added a commit to dyladan/opentelemetry-js that referenced this pull request Sep 9, 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
5 participants