Skip to content

Commit af42525

Browse files
committed
apm: address OTLP resource naming review
Keep legacy V1 naming unchanged and register url.template as a semantic concept for V2 lookups. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6b3ce287-79dc-4a9b-b16d-26179119b3d9
1 parent 6856b31 commit af42525

6 files changed

Lines changed: 21 additions & 29 deletions

File tree

pkg/trace/api/otlp.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ func (o *OTLPReceiver) convertSpan(res pcommon.Resource, lib pcommon.Instrumenta
741741
if transform.OperationAndResourceNameV2Enabled(o.conf) {
742742
span.Resource = transform.GetOTelResourceV2(in, res)
743743
} else {
744-
if r := resourceFromTags(span.Meta, in.Kind()); r != "" {
744+
if r := resourceFromTags(span.Meta); r != "" {
745745
span.Resource = r
746746
} else {
747747
span.Resource = in.Name()
@@ -756,16 +756,11 @@ func (o *OTLPReceiver) convertSpan(res pcommon.Resource, lib pcommon.Instrumenta
756756

757757
// resourceFromTags attempts to deduce a more accurate span resource from the given list of tags meta.
758758
// If this is not possible, it returns an empty string.
759-
func resourceFromTags(meta map[string]string, spanKind ptrace.SpanKind) string {
759+
func resourceFromTags(meta map[string]string) string {
760760
// `http.method` was renamed to `http.request.method` in the HTTP stabilization from v1.23.
761761
// See https://opentelemetry.io/docs/specs/semconv/http/migration-guide/#summary-of-changes
762762
if _, m := transform.GetFirstFromMap(meta, "http.request.method", "http.method"); m != "" {
763-
if spanKind == ptrace.SpanKindClient {
764-
if template := meta["url.template"]; template != "" {
765-
return m + " " + template
766-
}
767-
return m
768-
}
763+
// use the HTTP method + route (if available)
769764
if _, route := transform.GetFirstFromMap(meta, string(semconv.HTTPRouteKey), "grpc.path"); route != "" {
770765
return m + " " + route
771766
}

pkg/trace/api/otlp_test.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,9 +1612,8 @@ func TestOTLPHelpers(t *testing.T) {
16121612

16131613
t.Run("resourceFromTags", func(t *testing.T) {
16141614
for _, tt := range []struct {
1615-
meta map[string]string
1616-
spanKind ptrace.SpanKind
1617-
out string
1615+
meta map[string]string
1616+
out string
16181617
}{
16191618
{
16201619
meta: nil,
@@ -1628,16 +1627,6 @@ func TestOTLPHelpers(t *testing.T) {
16281627
meta: map[string]string{"http.method": "POST", "http.route": "/settings"},
16291628
out: "POST /settings",
16301629
},
1631-
{
1632-
meta: map[string]string{"http.method": "POST", "url.template": "/settings/{section}"},
1633-
spanKind: ptrace.SpanKindClient,
1634-
out: "POST /settings/{section}",
1635-
},
1636-
{
1637-
meta: map[string]string{"http.method": "POST", "http.route": "/settings"},
1638-
spanKind: ptrace.SpanKindClient,
1639-
out: "POST",
1640-
},
16411630
{
16421631
meta: map[string]string{"http.method": "POST", "grpc.path": "/settings"},
16431632
out: "POST /settings",
@@ -1679,7 +1668,7 @@ func TestOTLPHelpers(t *testing.T) {
16791668
out: "query myQuery",
16801669
},
16811670
} {
1682-
assert.Equal(t, tt.out, resourceFromTags(tt.meta, tt.spanKind))
1671+
assert.Equal(t, tt.out, resourceFromTags(tt.meta))
16831672
}
16841673
})
16851674

pkg/trace/otel/traceutil/otel_util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func TestGetOTelResource(t *testing.T) {
432432
name: "HTTP client method and URL template resource",
433433
sattrs: map[string]string{"http.request.method": "GET", "url.template": "/users/{user_id}"},
434434
spanKind: ptrace.SpanKindClient,
435-
expectedV1: "GET /users/{user_id}",
435+
expectedV1: "GET",
436436
expectedV2: "GET /users/{user_id}",
437437
},
438438
{

pkg/trace/semantics/mappings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@
316316
}
317317
]
318318
},
319+
"url.template": {
320+
"canonical": "url.template",
321+
"fallbacks": [
322+
{
323+
"name": "url.template",
324+
"provider": "otel",
325+
"type": "string"
326+
}
327+
]
328+
},
319329
"http.status_code": {
320330
"canonical": "http.status_code",
321331
"fallbacks": [

pkg/trace/semantics/semantics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
ConceptHTTPStatusCode Concept = "http.status_code"
5959
ConceptHTTPMethod Concept = "http.method"
6060
ConceptHTTPRoute Concept = "http.route"
61+
ConceptURLTemplate Concept = "url.template"
6162
ConceptGRPCStatusCode Concept = "rpc.grpc.status_code"
6263
ConceptSpanKind Concept = "span.kind"
6364
ConceptDDBaseService Concept = "_dd.base_service"

pkg/trace/transform/otelutil.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,9 @@ func GetOTelResourceV1(span ptrace.Span, res pcommon.Resource) (resName string)
292292
resName = GetOTelAttrValInResAndSpanAttrs(span, res, false, "resource.name")
293293
if resName == "" {
294294
if m := GetOTelAttrValInResAndSpanAttrs(span, res, false, "http.request.method", string(semconv.HTTPMethodKey)); m != "" {
295+
// use the HTTP method + route (if available)
295296
resName = m
296-
if span.Kind() == ptrace.SpanKindClient {
297-
if template := GetOTelAttrValInResAndSpanAttrs(span, res, false, "url.template"); template != "" {
298-
resName = resName + " " + template
299-
}
300-
} else if route := GetOTelAttrValInResAndSpanAttrs(span, res, false, string(semconv.HTTPRouteKey)); route != "" {
297+
if route := GetOTelAttrValInResAndSpanAttrs(span, res, false, string(semconv.HTTPRouteKey)); route != "" {
301298
resName = resName + " " + route
302299
}
303300
} else if m := GetOTelAttrValInResAndSpanAttrs(span, res, false, string(semconv.MessagingOperationKey)); m != "" {
@@ -349,7 +346,7 @@ func getOTelResourceV2[A semantics.Accessor](span ptrace.Span, accessor A) (resN
349346
}
350347
resName = m
351348
if span.Kind() == ptrace.SpanKindClient {
352-
if template := accessor.GetString("url.template"); template != "" {
349+
if template := lookupString(accessor, semantics.ConceptURLTemplate, false); template != "" {
353350
resName = resName + " " + template
354351
}
355352
} else if span.Kind() == ptrace.SpanKindServer {

0 commit comments

Comments
 (0)