From d76625f35f0cf2183bea609facb34d3a182ef72d Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Mon, 8 Apr 2024 20:24:58 +0200 Subject: [PATCH] [configuration] Allow ${env:ENV} notation for environment variable substitution (#3974) Fixes #3961 ## Changes Allows for the usage of the `${env:ENV}` syntax in SDK file configuration. This syntax is used in the OpenTelemetry Collector, see https://opentelemetry.io/docs/collector/configuration/#environment-variables for more information. This does not mean that other providers need to be supported; if we want to allow this we would need to reserve that syntax by rejecting `${:URI}` as invalid, since right now it would be left as-is. * [x] Related issues #3961, part of #3963 --------- Co-authored-by: jack-berg <34418638+jack-berg@users.noreply.github.com> --- CHANGELOG.md | 2 ++ specification/configuration/file-configuration.md | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d562eb6850..d05eadfc3c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,8 @@ release. - Clarify environment variable substitution is not recursive ([#3913](https://github.com/open-telemetry/opentelemetry-specification/pull/3913)) +- Allow `env:` prefix in environment variable substitution syntax. + ([#3974](https://github.com/open-telemetry/opentelemetry-specification/pull/3974)) ### Common diff --git a/specification/configuration/file-configuration.md b/specification/configuration/file-configuration.md index 4b34f951ed0..44debb95998 100644 --- a/specification/configuration/file-configuration.md +++ b/specification/configuration/file-configuration.md @@ -72,14 +72,14 @@ Configuration files support environment variables substitution for references which match the following regular expression: ```regexp -\$\{(?[a-zA-Z_][a-zA-Z0-9_]*)(:-(?[^\n]*))?} +\$\{(?:env:)?(?[a-zA-Z_][a-zA-Z0-9_]*)(:-(?[^\n]*))?} ``` The `ENV_NAME` MUST start with an alphabetic or `_` character, and is followed by 0 or more alphanumeric or `_` characters. -For example, `${API_KEY}` is valid, while `${1API_KEY}` and `${API_$KEY}` are -invalid. +For example, `${API_KEY}` and `${env:API_KEY}` are valid, while `${1API_KEY}` +and `${API_$KEY}` are invalid. Environment variable substitution MUST only apply to scalar values. Mapping keys are not candidates for substitution. @@ -115,6 +115,7 @@ export REPLACE_ME='${DO_NOT_REPLACE_ME}' # A valid replacement text ```yaml string_key: ${STRING_VALUE} # Valid reference to STRING_VALUE +env_string_key: ${env:STRING_VALUE} # Valid reference to STRING_VALUE other_string_key: "${STRING_VALUE}" # Valid reference to STRING_VALUE inside double quotes another_string_key: "${BOOl_VALUE}" # Valid reference to BOOl_VALUE inside double quotes yet_another_string_key: ${INVALID_MAP_VALUE} # Valid reference to INVALID_MAP_VALUE, but YAML structure from INVALID_MAP_VALUE MUST NOT be injected @@ -132,6 +133,7 @@ Environment variable substitution results in the following YAML: ```yaml string_key: value # Interpreted as type string, tag URI tag:yaml.org,2002:str +env_string_key: value # Interpreted as type string, tag URI tag:yaml.org,2002:str other_string_key: "value" # Interpreted as type string, tag URI tag:yaml.org,2002:str another_string_key: "true" # Interpreted as type string, tag URI tag:yaml.org,2002:str yet_another_string_key: "value\nkey:value" # Interpreted as type string, tag URI tag:yaml.org,2002:str