| 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/trace" |
| 11 |
) |
| 12 |
|
| 13 |
type tracerProviderWithAttributes struct { |
| 14 |
trace.TracerProvider |
| 15 |
attrs []attribute.KeyValue |
| 16 |
} |
| 17 |
|
| 18 |
func (tpwa tracerProviderWithAttributes) Tracer(name string, options ...trace.TracerOption) trace.Tracer { |
| 19 |
conf := trace.NewTracerConfig(options...) |
| 20 |
attrSet := conf.InstrumentationAttributes() |
| 21 |
// prepend our attributes so they can be overwritten |
| 22 |
newAttrs := append(slices.Clone(tpwa.attrs), attrSet.ToSlice()...) |
| 23 |
// append our attribute set option to overwrite the old one |
| 24 |
options = append(options, trace.WithInstrumentationAttributes(newAttrs...)) |
| 25 |
return tpwa.TracerProvider.Tracer(name, options...) |
| 26 |
} |
| 27 |
|
| 28 |
func (tpwa tracerProviderWithAttributes) Unwrap() trace.TracerProvider { |
| 29 |
return tpwa.TracerProvider |
| 30 |
} |
| 31 |
|
| 32 |
func (tpwa tracerProviderWithAttributes) DropInjectedAttributes(droppedAttrs ...string) trace.TracerProvider { |
| 33 |
return tracerProviderWithAttributes{ |
| 34 |
TracerProvider: tpwa.TracerProvider, |
| 35 |
attrs: slices.DeleteFunc(slices.Clone(tpwa.attrs), func(kv attribute.KeyValue) bool { |
| 36 |
return slices.Contains(droppedAttrs, string(kv.Key)) |
| 37 |
}), |
| 38 |
} |
| 39 |
} |