Otel.Configuration.Substitution (otel v0.2.0)

Copy Markdown View Source

Environment variable substitution for declarative configuration files (OTEL_CONFIG_FILE).

Implements spec configuration/data-model.md §Environment variable substitution (Status: Stable as of v1.55.0). Operates at the raw text level — substitution runs before YAML parsing so that the YAML parser interprets node types (boolean, integer, etc.) on the substituted values, satisfying spec MUST: "Node types MUST be interpreted after environment variable substitution takes place."

Pipeline used by Otel.Configuration:

File.read!(path)
|> Otel.Configuration.Substitution.substitute!()
|> Otel.Configuration.Parser.parse_string!()

Supported syntax

PatternResolves to
${VAR}env var VAR, or empty string if unset
${env:VAR}same as ${VAR} (explicit env prefix)
${VAR:-default}env var VAR, or default if unset / empty
${env:VAR:-default}same as above with explicit prefix
$$literal $ (escape)

Errors

  • Unsupported prefix (anything other than absent or env, e.g. ${sys:foo}) raises ArgumentError. Spec L362-L367 permits language-specific prefixes (MAY); we only honor env for now.
  • Invalid ENV-NAME (must match [a-zA-Z_][a-zA-Z0-9_]*, e.g. ${1FOO} or ${API_$KEY}) raises ArgumentError. Spec data-model.md L378-L382 mandates "the parser must return an empty result (no partial results are allowed) and an error describing the parse failure".
  • Unterminated ${ raises ArgumentError.

Public API

FunctionRole
substitute!/1SDK (Parse helper) — apply env-var substitution to raw text

References

  • Spec: opentelemetry-specification/specification/configuration/data-model.md §Environment variable substitution

Summary

Functions

Applies env-var substitution to raw per spec configuration/data-model.md §Environment variable substitution.

Functions

substitute!(raw)

@spec substitute!(raw :: binary()) :: binary()

Applies env-var substitution to raw per spec configuration/data-model.md §Environment variable substitution.

Raises ArgumentError on any malformed substitution reference.