From 93cb6c336cdbd395a530267f17b8e5c565f81ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20Tr=E1=BB=8Dng=20H=E1=BA=A3i?= <41283691+hainenber@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:22:41 +0700 Subject: [PATCH] feat(tracing): inject comp ID as instru scope attr (#5286) Signed-off-by: hainenber --- CHANGELOG.md | 2 ++ pkg/flow/tracing/wrap_tracer.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6f198c435d..9b44e14e5a5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -204,6 +204,8 @@ v0.37.0 (2023-10-10) - Fix initialization of the RAPL collector for the node_exporter integration and the prometheus.exporter.unix component. (@marctc) +- Set instrumentation scope attribute for traces emitted by Flow component. (@hainenber) + ### Other changes - Use Go 1.21.1 for builds. (@rfratto) diff --git a/pkg/flow/tracing/wrap_tracer.go b/pkg/flow/tracing/wrap_tracer.go index 9ffb5e7b4d38..197e7ce3200b 100644 --- a/pkg/flow/tracing/wrap_tracer.go +++ b/pkg/flow/tracing/wrap_tracer.go @@ -2,6 +2,8 @@ package tracing import ( "context" + "path/filepath" + "strings" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -41,6 +43,12 @@ type wrappedProvider struct { var _ trace.TracerProvider = (*wrappedProvider)(nil) func (wp *wrappedProvider) Tracer(name string, options ...trace.TracerOption) trace.Tracer { + // Inject the component name as instrumentation scope attribute. + // This would not have component's exact ID, aligning with OTEL's definition + if wp.id != "" { + otelComponentName := strings.TrimSuffix(wp.id, filepath.Ext(wp.id)) + options = append(options, trace.WithInstrumentationAttributes(attribute.String(wp.spanName, otelComponentName))) + } innerTracer := wp.inner.Tracer(name, options...) return &wrappedTracer{ inner: innerTracer,