Skip to content

Commit d76625f

Browse files
mx-psijack-berg
andauthored
[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 `${<provider>:URI}` as invalid, since right now it would be left as-is. * [x] Related issues #3961, part of #3963 --------- Co-authored-by: jack-berg <[email protected]>
1 parent 584b979 commit d76625f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ release.
5353

5454
- Clarify environment variable substitution is not recursive
5555
([#3913](https://github.com/open-telemetry/opentelemetry-specification/pull/3913))
56+
- Allow `env:` prefix in environment variable substitution syntax.
57+
([#3974](https://github.com/open-telemetry/opentelemetry-specification/pull/3974))
5658

5759
### Common
5860

specification/configuration/file-configuration.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ Configuration files support environment variables substitution for references
7272
which match the following regular expression:
7373

7474
```regexp
75-
\$\{(?<ENV_NAME>[a-zA-Z_][a-zA-Z0-9_]*)(:-(?<DEFAULT_VALUE>[^\n]*))?}
75+
\$\{(?:env:)?(?<ENV_NAME>[a-zA-Z_][a-zA-Z0-9_]*)(:-(?<DEFAULT_VALUE>[^\n]*))?}
7676
```
7777

7878
The `ENV_NAME` MUST start with an alphabetic or `_` character, and is followed
7979
by 0 or more alphanumeric or `_` characters.
8080

81-
For example, `${API_KEY}` is valid, while `${1API_KEY}` and `${API_$KEY}` are
82-
invalid.
81+
For example, `${API_KEY}` and `${env:API_KEY}` are valid, while `${1API_KEY}`
82+
and `${API_$KEY}` are invalid.
8383

8484
Environment variable substitution MUST only apply to scalar values. Mapping keys
8585
are not candidates for substitution.
@@ -115,6 +115,7 @@ export REPLACE_ME='${DO_NOT_REPLACE_ME}' # A valid replacement text
115115

116116
```yaml
117117
string_key: ${STRING_VALUE} # Valid reference to STRING_VALUE
118+
env_string_key: ${env:STRING_VALUE} # Valid reference to STRING_VALUE
118119
other_string_key: "${STRING_VALUE}" # Valid reference to STRING_VALUE inside double quotes
119120
another_string_key: "${BOOl_VALUE}" # Valid reference to BOOl_VALUE inside double quotes
120121
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:
132133
133134
```yaml
134135
string_key: value # Interpreted as type string, tag URI tag:yaml.org,2002:str
136+
env_string_key: value # Interpreted as type string, tag URI tag:yaml.org,2002:str
135137
other_string_key: "value" # Interpreted as type string, tag URI tag:yaml.org,2002:str
136138
another_string_key: "true" # Interpreted as type string, tag URI tag:yaml.org,2002:str
137139
yet_another_string_key: "value\nkey:value" # Interpreted as type string, tag URI tag:yaml.org,2002:str

0 commit comments

Comments
 (0)