Skip to content

pkg/trace/api: normalize span name before remapping for OTLP #12176

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

Closed
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
7 changes: 7 additions & 0 deletions pkg/trace/api/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ func (o *OTLPReceiver) convertSpan(rattr map[string]string, lib pcommon.Instrume
name = "opentelemetry." + name
}
}

normalized, err := traceutil.NormalizeName(name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced by this change. The remapping feature should remap the OpenTelemetry name to a new Datadog name, which gets normalised later on, if it has to. Doing this here will just create confusion and potential issues later on.

In my opinion, the current behaviour is better and the span name remappings should refer to the actual OpenTelemetry name, and not a Datadog normalized version of it.

Copy link
Author

Choose a reason for hiding this comment

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

@gbbr
Thank you for reviewing and the comment.

I got your point and yes, you're right.
Even though I created this pull request for the compatibility, I also think the current behavior is ideal.

So I'm happy to close this pull request, however it would be great if you mention the breaking change on the remapping feature and update the span_name_remappings example on in open-telemetry/opentelemetry-collector-contrib#9693

Thank you!

Copy link
Contributor

@gbbr gbbr May 31, 2022

Choose a reason for hiding this comment

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

Copy link
Author

@dragon3 dragon3 Jun 1, 2022

Choose a reason for hiding this comment

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

Thank you for adding to CHANGELOG.

If possible, I think it's better to update the example here as well:
https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/9693/files#diff-8c91465b7f1defd1410e697b702a817163bc88cee637ace3f202bb7f83321cb6

      #   go.opentelemetry.io_contrib_instrumentation_net_http_otelhttp.client: http.client

I'm closing this pull request.
Thank you!

if err != nil {
log.Warnf("failed to normalize span name, use default span name: %v", err)
}
name = normalized

if v, ok := o.conf.OTLPReceiver.SpanNameRemappings[name]; ok {
name = v
}
Expand Down
56 changes: 42 additions & 14 deletions pkg/trace/api/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,53 @@ var otlpTestTracesRequest = testutil.NewOTLPTracesRequest([]testutil.OTLPResourc

func TestOTLPNameRemapping(t *testing.T) {
cfg := config.New()
cfg.OTLPReceiver.SpanNameRemappings = map[string]string{"libname.unspecified": "new"}
cfg.OTLPReceiver.SpanNameRemappings = map[string]string{
"libname.unspecified": "new",
"go.opentelemetry.io_contrib_instrumentation_net_http_otelhttp.client": "http.client",
}
out := make(chan *Payload, 1)
rcv := NewOTLPReceiver(out, cfg)
rcv.ReceiveResourceSpans(testutil.NewOTLPTracesRequest([]testutil.OTLPResourceSpan{
for _, tt := range []struct {
in []testutil.OTLPResourceSpan
want string
}{
{
LibName: "libname",
LibVersion: "1.2",
Attributes: map[string]interface{}{},
Spans: []*testutil.OTLPSpan{
{Name: "asd"},
in: []testutil.OTLPResourceSpan{
{
LibName: "libname",
LibVersion: "1.2",
Attributes: map[string]interface{}{},
Spans: []*testutil.OTLPSpan{
{Name: "asd"},
},
},
},
want: "new",
},
}).Traces().ResourceSpans().At(0), http.Header{}, "")
timeout := time.After(500 * time.Millisecond)
select {
case <-timeout:
t.Fatal("timed out")
case p := <-out:
assert.Equal(t, "new", p.TracerPayload.Chunks[0].Spans[0].Name)
{
in: []testutil.OTLPResourceSpan{
{
LibName: "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
LibVersion: "1.0.0",
Attributes: map[string]interface{}{},
Spans: []*testutil.OTLPSpan{
{Name: "asd", Kind: ptrace.SpanKindClient},
},
},
},
want: "http.client",
},
} {
t.Run("", func(t *testing.T) {
rcv.ReceiveResourceSpans(testutil.NewOTLPTracesRequest(tt.in).Traces().ResourceSpans().At(0), http.Header{}, "")
timeout := time.After(500 * time.Millisecond)
select {
case <-timeout:
t.Fatal("timed out")
case p := <-out:
assert.Equal(t, tt.want, p.TracerPayload.Chunks[0].Spans[0].Name)
}
})
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
APM OTLP: Normalize span name before remapping for OTLP.