opentelemetry-collector/internal/telemetry/componentattribute
Jade Guiton f61313f4fa
Fix Logger.With followed by componentattribute.WithAttributeSet (#13610)
#### Description

This PR fixes a small bug in componentattribute, where adding fields to
a Logger with `Logger.With`, then calling
`componentattribute.WithAttributeSet` would silently fail to set
component attributes.

This is fixed by overriding the `Core.With` method on
`consoleCoreWithAttributes`, to make sure that we wrap the modified
inner core in a `consoleCoreWithAttributes` before returning it.

I added an `extraFields` field to `consoleCoreWithAttributes` so we can
ensure Zap Fields are added in the same order (first component
attributes, then custom user fields) when updating the component
attributes.

This bug doesn't affect `otelTeeCoreWithAttributes`, which already does
this.

The `componentattribute` API is currently internal, and none of the
components that use it (the memorylimiter processor and OTLP receiver)
use `Logger.With`, so there is currently no way to trigger this bug,
hence the lack of a changelog.

#### Testing

I added a unit test which checks this specific use case. I confirmed
that it failed before the change and now succeeds.
2025-08-11 18:24:47 +00:00
..
attribute.go Inject component-identifying scope attributes (#12617) 2025-03-28 12:15:25 +00:00
logger_test.go Fix Logger.With followed by componentattribute.WithAttributeSet (#13610) 2025-08-11 18:24:47 +00:00
logger_zap.go Fix Logger.With followed by componentattribute.WithAttributeSet (#13610) 2025-08-11 18:24:47 +00:00
meter_provider.go [chore]: fix staticcheck exclusions (#12792) 2025-04-02 20:07:55 +00:00
meter_test.go Inject component-identifying scope attributes (#12617) 2025-03-28 12:15:25 +00:00
tracer_provider.go [chore]: enable-all rules from go-critic (#13433) 2025-07-24 10:34:03 +00:00
tracer_test.go Inject component-identifying scope attributes (#12617) 2025-03-28 12:15:25 +00:00