Skip to content

Commit

Permalink
[configuration] Allow ${env:ENV} notation for environment variable su…
Browse files Browse the repository at this point in the history
…bstitution (#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 <34418638+jack-berg@users.noreply.github.com>
  • Loading branch information
mx-psi and jack-berg committed Apr 8, 2024
1 parent 584b979 commit d76625f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions specification/configuration/file-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ Configuration files support environment variables substitution for references
which match the following regular expression:

```regexp
\$\{(?<ENV_NAME>[a-zA-Z_][a-zA-Z0-9_]*)(:-(?<DEFAULT_VALUE>[^\n]*))?}
\$\{(?:env:)?(?<ENV_NAME>[a-zA-Z_][a-zA-Z0-9_]*)(:-(?<DEFAULT_VALUE>[^\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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d76625f

Please sign in to comment.