Otel.SDK.Config (otel v0.2.0)

Copy Markdown View Source

Composes provider configuration from three layers, in precedence order from highest to lowest:

  1. 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's start_link config.)
  2. OS env (OTEL_*) — spec configuration/sdk-environment-variables.md L48-L50: "Implementations MAY choose to allow configuration via the environment variables ... they SHOULD use the names and value parsing behavior specified in this document."
  3. Application envApplication.get_env(:otel, pillar, []). Lets users configure the SDK declaratively from config/runtime.exs or config/<env>.exs.
  4. Built-in defaults — defined inline below; mirror the spec defaults (sampler parentbased_always_on, exporter otlp, processor batch, 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

FunctionReturns
disabled?/0OTEL_SDK_DISABLED == true; Application.start/2 skips registering providers when true
trace/0TracerProvider config map
metrics/0MeterProvider config map
logs/0LoggerProvider config map
propagator/0Global 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 by Otel.ConfigurationOtel.SDK.Application detects the env var and routes through Otel.Configuration.load!/0.
  • OTLP exporter knobs (OTEL_EXPORTER_OTLP_*) — already read by each Otel.OTLP.<Pillar>.Exporter.HTTP module on its own. The SDK config layer only selects which exporter; the chosen exporter parses its own env vars at init/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

disabled?()

@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."

logs()

@spec logs() :: map()

Builds the LoggerProvider config map.

metrics()

@spec metrics() :: map()

Builds the MeterProvider config map.

propagator()

@spec propagator() :: module() | {module(), [module()]}

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.Noop module 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, [...]} from Composite.new/1 for 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.

trace()

@spec trace() :: map()

Builds the TracerProvider config map by composing defaults, Application env, and OTEL_* env vars.