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
| Pattern | Resolves 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}) raisesArgumentError. Spec L362-L367 permits language-specific prefixes (MAY); we only honorenvfor now. - Invalid
ENV-NAME(must match[a-zA-Z_][a-zA-Z0-9_]*, e.g.${1FOO}or${API_$KEY}) raisesArgumentError. Specdata-model.mdL378-L382 mandates "the parser must return an empty result (no partial results are allowed) and an error describing the parse failure". - Unterminated
${raisesArgumentError.
Public API
| Function | Role |
|---|---|
substitute!/1 | SDK (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
Applies env-var substitution to raw per spec
configuration/data-model.md §Environment variable substitution.
Raises ArgumentError on any malformed substitution reference.