opentelemetry-java icon indicating copy to clipboard operation
opentelemetry-java copied to clipboard

Create resource from environment

Open oliver-zhang opened this issue 1 year ago • 2 comments

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:

  1. if the attribute value not contains {, return the value directly
  2. if the attribute value contains {, find attribute value key (ENV2) and get value from system env or system properties, return value if not null
  3. if system env or system properties do not have this key return default value

oliver-zhang avatar Jun 26 '23 07:06 oliver-zhang

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?

jack-berg avatar Jun 26 '23 16:06 jack-berg

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

  1. 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}
  2. If user not use environment variables but use system properties, what should they do?

oliver-zhang avatar Jun 28 '23 06:06 oliver-zhang