fix: outputs.opentelemetry use attributes setting (#9588)
This commit is contained in:
parent
0317d7c3db
commit
147e3d1389
|
|
@ -160,6 +160,14 @@ func (o *OpenTelemetry) Write(metrics []telegraf.Metric) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if len(o.Attributes) > 0 {
|
||||
for i := 0; i < md.ResourceMetrics().Len(); i++ {
|
||||
for k, v := range o.Attributes {
|
||||
md.ResourceMetrics().At(i).Resource().Attributes().UpsertString(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(o.Timeout))
|
||||
|
||||
if len(o.Headers) > 0 {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ func TestOpenTelemetry(t *testing.T) {
|
|||
{
|
||||
rm := expect.ResourceMetrics().AppendEmpty()
|
||||
rm.Resource().Attributes().InsertString("host.name", "potato")
|
||||
rm.Resource().Attributes().InsertString("attr-key", "attr-val")
|
||||
ilm := rm.InstrumentationLibraryMetrics().AppendEmpty()
|
||||
ilm.InstrumentationLibrary().SetName("My Library Name")
|
||||
m := ilm.Metrics().AppendEmpty()
|
||||
|
|
@ -45,6 +46,7 @@ func TestOpenTelemetry(t *testing.T) {
|
|||
ServiceAddress: m.Address(),
|
||||
Timeout: config.Duration(time.Second),
|
||||
Headers: map[string]string{"test": "header1"},
|
||||
Attributes: map[string]string{"attr-key": "attr-val"},
|
||||
metricsConverter: metricsConverter,
|
||||
grpcClientConn: m.GrpcClient(),
|
||||
metricsServiceClient: otlpgrpc.NewMetricsClient(m.GrpcClient()),
|
||||
|
|
|
|||
Loading…
Reference in New Issue