Skip to content

${env:VAR:-} with empty default resolves to nil instead of empty string, causing downstream validation failures #14587

@57Ajay

Description

@57Ajay

Component(s)

confmap

What happened?

Description

Observed Behavior

When using an environment expansion with an empty default:

value: "${env:VAR:-}"

and VAR is unset, the resulting value resolves to nil instead of an empty string.

This appears to happen because the envprovider ultimately passes an empty byte slice to NewRetrievedFromYAML, which results in the YAML unmarshaler producing a nil value.


Impact

This leads to validation failures in downstream components that rely on distinguishing between:

  • field not set (nil)
  • field explicitly set to empty string ("")

For example, in the attraction processor, validation checks:

if a.Value != nil

Since the expanded value becomes nil, the processor treats the field as missing, even though the user explicitly specified it via ${env:VAR:-}.


Expected Behavior

If a user explicitly provides:

value: "${env:VAR:-}"

and the default resolves to an empty string, the resolved value should likely be:

""

rather than nil, preserving the semantic difference between:

  • omitted field
  • explicitly empty value

Question

Is nil the intended representation for an empty environment expansion in OTel config?

If not, would it make sense for envprovider to preserve empty defaults as explicit empty strings instead of allowing them to collapse into nil during YAML unmarshaling?


Related

This behavior causes a failure in the contrib repository:
open-telemetry/opentelemetry-collector-contrib#46085

Collector version

292ea8f

Environment information

Environment

OS: Ubuntu 24.04
Compiler: go1.25.7 linux/amd64

OpenTelemetry Collector configuration

receivers:
  nop:

processors:
  resource/foo:
    attributes:
      - key: foo
        value: "${env:BAR:-}"
        action: upsert

exporters:
  nop:

service:
  pipelines:
    metrics:
      receivers: [nop]
      processors: [resource/foo]
      exporters: [nop]

Log output

2026-02-14T14:35:01.331Z        error   service@v0.145.1-0.20260212100729-5a059d1d6718/service.go:165   error found during service initialization       {"resource": {"service.instance.id": "f5ffaa7b-1da9-442d-8346-5af7a8ab84aa", "service.name": "otelcontribcol", "service.version": "0.145.0-dev"}, "error": "failed to build pipelines: failed to create \"resource/foo\" processor, in pipeline \"metrics\": error with key \"foo\" (0-th action): error creating AttrProc. Either field \"value\", \"from_attribute\", \"from_context\", or \"default_value\" must be specified"}
go.opentelemetry.io/collector/service.New.func2
        go.opentelemetry.io/collector/service@v0.145.1-0.20260212100729-5a059d1d6718/service.go:165
go.opentelemetry.io/collector/service.New
        go.opentelemetry.io/collector/service@v0.145.1-0.20260212100729-5a059d1d6718/service.go:232
go.opentelemetry.io/collector/otelcol.(*Collector).setupConfigurationComponents
        go.opentelemetry.io/collector/otelcol@v0.145.1-0.20260212100729-5a059d1d6718/collector.go:211
go.opentelemetry.io/collector/otelcol.(*Collector).Run
        go.opentelemetry.io/collector/otelcol@v0.145.1-0.20260212100729-5a059d1d6718/collector.go:329
go.opentelemetry.io/collector/otelcol.NewCommand.func1
        go.opentelemetry.io/collector/otelcol@v0.145.1-0.20260212100729-5a059d1d6718/command.go:39
github.com/spf13/cobra.(*Command).execute
        github.com/spf13/cobra@v1.10.2/command.go:1015
github.com/spf13/cobra.(*Command).ExecuteC
        github.com/spf13/cobra@v1.10.2/command.go:1148
github.com/spf13/cobra.(*Command).Execute
        github.com/spf13/cobra@v1.10.2/command.go:1071
main.runInteractive
        github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontribcol/main.go:72
main.run
        github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontribcol/main_others.go:10
main.main
        github.com/open-telemetry/opentelemetry-collector-contrib/cmd/otelcontribcol/main.go:63
runtime.main
        runtime/proc.go:285
Error: failed to build pipelines: failed to create "resource/foo" processor, in pipeline "metrics": error with key "foo" (0-th action): error creating AttrProc. Either field "value", "from_attribute", "from_context", or "default_value" must be specified

Additional context

NOTE: the above config and it's output is replication of bug #46085 from opentelemetry-collector-contrib repo.

issue: issue-url

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions