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: ReferenceError when OTEL_TRACES_SAMPLER used without OTEL_TRACES_SAMPLER_ARG #2434

Merged
merged 1 commit into from
Aug 27, 2021

Conversation

hermanbanken
Copy link
Contributor

@hermanbanken hermanbanken commented Aug 27, 2021

Which problem is this PR solving?

When OTEL_TRACES_SAMPLER is used without OTEL_TRACES_SAMPLER_ARG there would be a ReferenceError due to getSamplerProbabilityFromEnv being called above the definition of DEFAULT_RATIO.

ReferenceError: Cannot access 'DEFAULT_RATIO' before initialization
    at null.getSamplerProbabilityFromEnv (/app/node_modules/@opentelemetry/tracing/src/config.ts:91:58)
    at null.buildSamplerFromEnv (/app/node_modules/@opentelemetry/tracing/src/config.ts:71:44)
    at Object.<anonymous> (/app/node_modules/@opentelemetry/tracing/src/config.ts:38:12)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:784:16)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/app/node_modules/@opentelemetry/tracing/src/utility.ts:17:1)

Short description of the changes

Moving constant higher up in the code.

When OTEL_TRACES_SAMPLER is used without OTEL_TRACES_SAMPLER_ARG there would be a ReferenceError due to getSamplerProbabilityFromEnv being called above the definition of DEFAULT_RATIO.

```
ReferenceError: Cannot access 'DEFAULT_RATIO' before initialization
    at null.getSamplerProbabilityFromEnv (/app/node_modules/@opentelemetry/tracing/src/config.ts:91:58)
    at null.buildSamplerFromEnv (/app/node_modules/@opentelemetry/tracing/src/config.ts:71:44)
    at Object.<anonymous> (/app/node_modules/@opentelemetry/tracing/src/config.ts:38:12)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:784:16)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (/app/node_modules/@opentelemetry/tracing/src/utility.ts:17:1)```
@hermanbanken hermanbanken requested a review from a team August 27, 2021 15:02
@linux-foundation-easycla

This comment has been minimized.

@hermanbanken
Copy link
Contributor Author

Signed the CLA. Please recheck.

@codecov
Copy link

codecov bot commented Aug 27, 2021

Codecov Report

Merging #2434 (ce7dfb1) into main (4ff1c6c) will decrease coverage by 0.14%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2434      +/-   ##
==========================================
- Coverage   92.70%   92.55%   -0.15%     
==========================================
  Files         137      134       -3     
  Lines        4990     4865     -125     
  Branches     1054     1033      -21     
==========================================
- Hits         4626     4503     -123     
+ Misses        364      362       -2     
Impacted Files Coverage Δ
...ackages/opentelemetry-sdk-trace-base/src/config.ts 86.84% <100.00%> (ø)
...ontext-async-hooks/src/AsyncHooksContextManager.ts
...async-hooks/src/AsyncLocalStorageContextManager.ts
...sync-hooks/src/AbstractAsyncHooksContextManager.ts

@dyladan dyladan changed the title Fix ReferenceError fix: ReferenceError when OTEL_TRACES_SAMPLER used without OTEL_TRACES_SAMPLER_ARG Aug 27, 2021
@dyladan dyladan added the bug Something isn't working label Aug 27, 2021
@dyladan

This comment has been minimized.

@obecny obecny merged commit dfb597d into open-telemetry:main Aug 27, 2021
@dyladan dyladan mentioned this pull request Sep 13, 2021
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.

4 participants