Skip to content

Commit

Permalink
fix: outputs.opentelemetry use attributes setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Boten committed Aug 4, 2021
1 parent 0270c3b commit 8d852c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugins/outputs/opentelemetry/opentelemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions plugins/outputs/opentelemetry/opentelemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()),
Expand Down

0 comments on commit 8d852c4

Please sign in to comment.