Otel.SDK.Config.Env (otel v0.2.0)

Copy Markdown View Source

Spec-compliant typed reads of OTEL_* environment variables.

Implements the value-parsing semantics from configuration/sdk-environment-variables.md L48-L107 (parse rules) and configuration/common.md L77-L102 (Duration / Timeout).

All readers return nil when the variable is unset or when its value fails to parse — and emit a Logger.warning per the spec guidance attached to each parse rule. Callers treat nil as "fall through to the next layer" (Application env → built-in default), giving a clean three-layer composition.

Public API

FunctionSpec rule
string/1L60 — empty value MUST be treated as unset
boolean/1L66-L76 — only case-insensitive "true" is true
integer/1L88-L90 — SHOULD warn + treat as unset on unparseable
duration_ms/1common.md L77-L82 — non-negative milliseconds
timeout_ms/1common.md L92-L102 — 0 SHOULD mean infinite
enum/2L103-L107 — case-insensitive; unknown MUST warn + ignore
list/1comma-separated; empty entries dropped

References

  • OTel SDK env vars: opentelemetry-specification/specification/configuration/sdk-environment-variables.md
  • OTel SDK common: opentelemetry-specification/specification/configuration/common.md

Summary

Functions

Reads var as a boolean. Spec L66-L76 — only case-insensitive "true" is true; everything else is false. Unparseable values fall to false with a warning.

Reads var as a Duration in milliseconds. common.md L77-L82 — non-negative milliseconds. Negative values warn and are ignored.

Reads var as an enum, matching its lowercased value against the allowed atoms (compared by their Atom.to_string/1 form). Spec L103-L107 — unknown values MUST warn and be ignored.

Reads var as an integer. Spec L88-L90 — unparseable values SHOULD warn and be treated as unset.

Reads var as a comma-separated list of trimmed, non-empty strings. Returns nil when the variable is unset.

Reads var as a string. Spec L60 — empty value MUST be unset.

Reads var as a Timeout in milliseconds. common.md L92-L102 — 0 SHOULD mean no limit (returned as :infinity).

Functions

boolean(var)

@spec boolean(var :: String.t()) :: boolean() | nil

Reads var as a boolean. Spec L66-L76 — only case-insensitive "true" is true; everything else is false. Unparseable values fall to false with a warning.

duration_ms(var)

@spec duration_ms(var :: String.t()) :: non_neg_integer() | nil

Reads var as a Duration in milliseconds. common.md L77-L82 — non-negative milliseconds. Negative values warn and are ignored.

enum(var, allowed)

@spec enum(var :: String.t(), allowed :: [atom()]) :: atom() | nil

Reads var as an enum, matching its lowercased value against the allowed atoms (compared by their Atom.to_string/1 form). Spec L103-L107 — unknown values MUST warn and be ignored.

integer(var)

@spec integer(var :: String.t()) :: integer() | nil

Reads var as an integer. Spec L88-L90 — unparseable values SHOULD warn and be treated as unset.

list(var)

@spec list(var :: String.t()) :: [String.t()] | nil

Reads var as a comma-separated list of trimmed, non-empty strings. Returns nil when the variable is unset.

Note: spec L118 mandates dedup only for OTEL_PROPAGATORS; this helper does not dedup — call sites that need it must do so.

string(var)

@spec string(var :: String.t()) :: String.t() | nil

Reads var as a string. Spec L60 — empty value MUST be unset.

timeout_ms(var)

@spec timeout_ms(var :: String.t()) :: non_neg_integer() | :infinity | nil

Reads var as a Timeout in milliseconds. common.md L92-L102 — 0 SHOULD mean no limit (returned as :infinity).