Skip to content

Commit

Permalink
Fix ReferenceError (#2434)
Browse files Browse the repository at this point in the history
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)```
  • Loading branch information
hermanbanken committed Aug 27, 2021
1 parent 4ff1c6c commit dfb597d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions packages/opentelemetry-sdk-trace-base/src/config.ts
Expand Up @@ -27,6 +27,7 @@ import {

const env = getEnv();
const FALLBACK_OTEL_TRACES_SAMPLER = TracesSamplerValues.AlwaysOn;
const DEFAULT_RATIO = 1;

/**
* Default configuration. For fields with primitive values, any user-provided
Expand Down Expand Up @@ -79,8 +80,6 @@ export function buildSamplerFromEnv(
}
}

const DEFAULT_RATIO = 1;

function getSamplerProbabilityFromEnv(
env: Required<ENVIRONMENT>
): number | undefined {
Expand Down

0 comments on commit dfb597d

Please sign in to comment.