Composes provider configuration from three layers, in precedence order from highest to lowest:
- Programmatic — anything the caller passes directly to a
provider's
start_link(config: ...)overrides every layer below. (Outside this module's scope: providers receive the map this module produces and merge it with the caller'sstart_linkconfig.) - OS env (
OTEL_*) — specconfiguration/sdk-environment-variables.mdL48-L50: "Implementations MAY choose to allow configuration via the environment variables ... they SHOULD use the names and value parsing behavior specified in this document." - Application env —
Application.get_env(:otel, pillar, []). Lets users configure the SDK declaratively fromconfig/runtime.exsorconfig/<env>.exs. - Built-in defaults — defined inline below; mirror the spec
defaults (sampler
parentbased_always_on, exporterotlp, processorbatch, etc.).
Configuration UX
# config/runtime.exs
config :otel,
trace: [
sampler: :parentbased_always_on,
exporter: :otlp, # short form, blessed names
processor: :batch,
span_limits: %{attribute_count_limit: 256}
],
metrics: [
exporter: :otlp,
export_interval_ms: 30_000
],
logs: [
exporter: {MyApp.CustomExporter, %{api_key: System.get_env("X")}},
processor: :batch
]All exporter / processor / sampler values accept the three forms
documented in Otel.SDK.Config.Selector.
Public API
| Function | Returns |
|---|---|
disabled?/0 | OTEL_SDK_DISABLED == true; Application.start/2 skips registering providers when true |
trace/0 | TracerProvider config map |
metrics/0 | MeterProvider config map |
logs/0 | LoggerProvider config map |
propagator/0 | Global TextMap propagator (single module or {Composite, [...]}) |
Out of scope (future PRs)
OTEL_CONFIG_FILE(declarative YAML) — when set, spec L332 "all other env vars... MUST be ignored". A whole-config short-circuit; handled byOtel.Configuration—Otel.SDK.Applicationdetects the env var and routes throughOtel.Configuration.load!/0.- OTLP exporter knobs (
OTEL_EXPORTER_OTLP_*) — already read by eachOtel.OTLP.<Pillar>.Exporter.HTTPmodule on its own. The SDK config layer only selects which exporter; the chosen exporter parses its own env vars atinit/1.
References
- OTel SDK env vars:
opentelemetry-specification/specification/configuration/sdk-environment-variables.md - OTel Trace SDK:
opentelemetry-specification/specification/trace/sdk.md - OTel Metrics SDK:
opentelemetry-specification/specification/metrics/sdk.md - OTel Logs SDK:
opentelemetry-specification/specification/logs/sdk.md
Summary
Functions
Returns true when OTEL_SDK_DISABLED=true (case-insensitive).
Builds the LoggerProvider config map.
Builds the MeterProvider config map.
Builds the global TextMap propagator value to install via
Otel.API.Propagator.TextMap.set_propagator/1.
Builds the TracerProvider config map by composing defaults,
Application env, and OTEL_* env vars.
Functions
@spec disabled?() :: boolean()
Returns true when OTEL_SDK_DISABLED=true (case-insensitive).
Spec L113-L114 — "Disable the SDK for all signals... If true,
a no-op SDK implementation will be used for all telemetry signals.
Any propagators set via the OTEL_PROPAGATORS environment variable
will be non-no-op."
@spec logs() :: map()
Builds the LoggerProvider config map.
@spec metrics() :: map()
Builds the MeterProvider config map.
Builds the global TextMap propagator value to install via
Otel.API.Propagator.TextMap.set_propagator/1.
Spec L122-L131 (OTEL_PROPAGATORS): comma-separated list of
propagator names, default "tracecontext,baggage". Values
MUST be deduplicated (L118).
Returns:
- the
Otel.API.Propagator.TextMap.Noopmodule when the list is empty or contains"none"(spec L130 — "No automatically configured propagator"); - a single propagator module when the list has one entry;
{Otel.API.Propagator.TextMap.Composite, [...]}fromComposite.new/1for two or more entries.
Mix Config (config :otel, propagators: [...]) takes
precedence over OTEL_PROPAGATORS. The list may contain
shortcut atoms (:tracecontext, :baggage, :none) or
custom propagator modules; see Otel.SDK.Config.Selector.propagator/1
for the full mapping.
@spec trace() :: map()
Builds the TracerProvider config map by composing defaults,
Application env, and OTEL_* env vars.