[confmap] Struct fields silently ignored implementing Unmarshaler with mapstructure:",squash"

Author: kennytrytek-wfCreated Sep 18, 2026Updated Sep 21, 2026
Labelsbugneeds triage

Component(s)

confmap

What happened?

Describe the bug

When a struct embeds another struct with mapstructure:",squash" and the embedded type implements confmap.Unmarshaler, the outer struct's own fields are silently ignored during unmarshaling — they retain zero/default values regardless of what the source map contains.

Steps to reproduce

// Outer struct embeds a type that implements confmap.Unmarshaler.
type Config struct {
    confighttp.ServerConfig `mapstructure:",squash"` // implements confmap.Unmarshaler
    Path string `mapstructure:"path"`
}

conf := confmap.NewFromStringMap(map[string]any{
    "endpoint": "0.0.0.0:4327",
    "path":     "/events",
})
cfg := &Config{}
_ = conf.Unmarshal(cfg)

fmt.Println(cfg.Path)             // ""
fmt.Println(cfg.NetAddr.Endpoint) // "0.0.0.0:4327"

What did you expect to see?

cfg.Path == "/events" — the outer struct's fields decoded from the source map alongside the embedded struct's fields.

What did you see instead?

cfg.Path == "" — the outer struct's own fields are silently dropped. unmarshalerEmbeddedStructsHookFunc calls the embedded struct's Unmarshal (which correctly decodes endpoint into ServerConfig), but the subsequent decode of the outer struct's remaining fields does not run correctly, leaving Path at its zero value.

Collector version

v0.160.0, go.opentelemetry.io/collector/[email protected]

Environment information

No response

OpenTelemetry Collector configuration

yaml

Log output

bash

Additional context

No response

Tip

No response

Source: open-telemetry/opentelemetry-collector