opentelemetry-java
opentelemetry-java copied to clipboard
Create resource from environment
Related to #5554, we can create resource attributes from Environment
If we otel.resource.attributes
like this: key1=value1,key2={ENV2:defaultValue}
can we get actually value from the following steps:
- if the attribute value not contains
{
, return the value directly - if the attribute value contains
{
, find attribute value key (ENV2) and get value from system env or system properties, return value if not null - if system env or system properties do not have this key return default value
The behavior of parsing this environment variable is dictated by the specification here.
The spec would need to be updated to include this new behavior, which is possible, but I think unlikely because its possible to achieve the desired affect without any new behavioral requirements on the SDK:
export OTEL_RESOURCE_ATTRIBUTES=key1=value1
export ENV2=foo
export OTEL_RESOURCE_ATTRIBUTES="${OTEL_RESOURCE_ATTRIBUTES},key2=${ENV2:bar}"
If a shell can already perform substitutions, why burden the SDK with additional responsibilities?
The behavior of parsing this environment variable is dictated by the specification here.
The spec would need to be updated to include this new behavior, which is possible, but I think unlikely because its possible to achieve the desired affect without any new behavioral requirements on the SDK:
export OTEL_RESOURCE_ATTRIBUTES=key1=value1 export ENV2=foo export OTEL_RESOURCE_ATTRIBUTES="${OTEL_RESOURCE_ATTRIBUTES},key2=${ENV2:bar}"
If a shell can already perform substitutions, why burden the SDK with additional responsibilities?
This can be achieved through a shell , but i think it have some following problems
- The configuration is bit complicated, and user can not set default value when variable is not exist
export OTEL_RESOURCE_ATTRIBUTES="${OTEL_RESOURCE_ATTRIBUTES},key2=${ENV2:bar}"
it can not be set ${ENV2:bar} - If user not use environment variables but use system properties, what should they do?