Skip to content

[CONFIGURATION] Support setting attributes from environment variable #4473

Description

@dbarker

Background

Support for substituting environment variables as attribute values is needed.

See: configuration/data-model/#environment-variable-substitution).

The common example is to set service.name from OTEL_SERVICE_NAME as below.

resource:
  attributes:
    - name: service.name
      value: ${OTEL_SERVICE_NAME}
  detection/development:
    detectors:  
       - my_detector:

The AttributeNameValue nullBehavior is to ignore unset/null values. This means if OTEL_SERVICE_NAME is not set then the parser must ignore the service.name attribute in resource.attributes.

For example: In this configuration if my_detector sets service.name and OTEL_SERVICE_NAME is also set then the attribute value from the detector is overridden with the value from OTEL_SERVICE_NAME. If the env var is not set then the attribute from the detector must be used.

Scope:

  • Add environment variable substitution support for all attribute value types to the YAML parser along with support for null value detection.
  • Update the ConfigurationParser and SdkBuilder to only set attrbutes that have non-null values.
  • Add unit tests for parsing all attribute value types and a programmatic test for the above use case

Metadata

Metadata

Assignees

Labels

triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions