Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracing): inject component ID as instrumentation scope attribute #5286

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ v0.37.0-rc.1 (2023-10-06)
- 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)
Expand Down
8 changes: 8 additions & 0 deletions pkg/flow/tracing/wrap_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package tracing

import (
"context"
"path/filepath"
"strings"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -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)))
}
Comment on lines +46 to +51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the exact ID of the component still get set on the span?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the old function isn't removed, yet ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, just double checking :)

innerTracer := wp.inner.Tracer(name, options...)
return &wrappedTracer{
inner: innerTracer,
Expand Down