| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package componentattribute // import "go.opentelemetry.io/collector/service/internal/componentattribute" |
| 5 |
|
| 6 |
import ( |
| 7 |
"slices" |
| 8 |
|
| 9 |
"go.opentelemetry.io/otel/attribute" |
| 10 |
"go.opentelemetry.io/otel/metric" |
| 11 |
) |
| 12 |
|
| 13 |
type meterProviderWithAttributes struct { |
| 14 |
metric.MeterProvider |
| 15 |
attrs []attribute.KeyValue |
| 16 |
} |
| 17 |
|
| 18 |
func (mpwa meterProviderWithAttributes) Meter(name string, opts ...metric.MeterOption) metric.Meter { |
| 19 |
conf := metric.NewMeterConfig(opts...) |
| 20 |
attrSet := conf.InstrumentationAttributes() |
| 21 |
// prepend our attributes so they can be overwritten |
| 22 |
newAttrs := append(slices.Clone(mpwa.attrs), attrSet.ToSlice()...) |
| 23 |
// append our attribute set option to overwrite the old one |
| 24 |
opts = append(opts, metric.WithInstrumentationAttributes(newAttrs...)) |
| 25 |
return mpwa.MeterProvider.Meter(name, opts...) |
| 26 |
} |
| 27 |
|
| 28 |
func (mpwa meterProviderWithAttributes) DropInjectedAttributes(droppedAttrs ...string) metric.MeterProvider { |
| 29 |
return meterProviderWithAttributes{ |
| 30 |
MeterProvider: mpwa.MeterProvider, |
| 31 |
attrs: slices.DeleteFunc(slices.Clone(mpwa.attrs), func(kv attribute.KeyValue) bool { |
| 32 |
return slices.Contains(droppedAttrs, string(kv.Key)) |
| 33 |
}), |
| 34 |
} |
| 35 |
} |