Skip to content

Commit

Permalink
fix(sdk-trace-base): don't load envs top level
Browse files Browse the repository at this point in the history
Right now `@opentelemetry/sdk-trace-base` loads `OTEL_*` env vars when it is loaded, regardless of if `loadDefaultConfig` is ever called. In runtimes with a permission model like Deno, this may cause a bunch of permission prompts right on startup. This PR changes the env vars to all be loaded when `loadDefaultConfig` is called.

Interestingly, previously only `buildSamplerFromEnv` used the "global" env vars. For all other options the env vars are re-read on every call to `loadDefaultConfig`.
  • Loading branch information
lucacasonato committed Dec 4, 2024
1 parent 85dcbc7 commit b31a8cd
Showing 1 changed file with 9 additions and 10 deletions.
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 b31a8cd

Please sign in to comment.