Skip to content

Commit

Permalink
fix(sdk-trace-base): don't load envs top level (#5233)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Dec 4, 2024
1 parent 85dcbc7 commit 97dff5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ For semantic convention package changes, see the [semconv CHANGELOG](packages/se

### :bug: (Bug Fix)

* fix(sdk-trace-base): do not load OTEL_ env vars on module load, but when needed [#5224](https://github.com/open-telemetry/opentelemetry-js/pull/5224)

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
19 changes: 9 additions & 10 deletions packages/opentelemetry-sdk-trace-base/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { AlwaysOnSampler } from './sampler/AlwaysOnSampler';
import { ParentBasedSampler } from './sampler/ParentBasedSampler';
import { TraceIdRatioBasedSampler } from './sampler/TraceIdRatioBasedSampler';

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

Expand All @@ -36,23 +35,23 @@ const DEFAULT_RATIO = 1;
// object needs to be wrapped in this function and called when needed otherwise
// envs are parsed before tests are ran - causes tests using these envs to fail
export function loadDefaultConfig() {
const _env = getEnv();
const env = getEnv();

return {
sampler: buildSamplerFromEnv(env),
forceFlushTimeoutMillis: 30000,
generalLimits: {
attributeValueLengthLimit: _env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT,
attributeCountLimit: _env.OTEL_ATTRIBUTE_COUNT_LIMIT,
attributeValueLengthLimit: env.OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT,
attributeCountLimit: env.OTEL_ATTRIBUTE_COUNT_LIMIT,
},
spanLimits: {
attributeValueLengthLimit: _env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT,
attributeCountLimit: _env.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
linkCountLimit: _env.OTEL_SPAN_LINK_COUNT_LIMIT,
eventCountLimit: _env.OTEL_SPAN_EVENT_COUNT_LIMIT,
attributeValueLengthLimit: env.OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT,
attributeCountLimit: env.OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT,
linkCountLimit: env.OTEL_SPAN_LINK_COUNT_LIMIT,
eventCountLimit: env.OTEL_SPAN_EVENT_COUNT_LIMIT,
attributePerEventCountLimit:
_env.OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT,
attributePerLinkCountLimit: _env.OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT,
env.OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT,
attributePerLinkCountLimit: env.OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT,
},
mergeResourceWithDefaults: true,
};
Expand Down

0 comments on commit 97dff5b

Please sign in to comment.