Skip to content

Commit 57d6045

Browse files
authored
feat(opentelemetry): Support new http method attribute (#11756)
Fixes #11755 OpenTelemetry restructured their http semantic conventions and declared them stable: https://opentelemetry.io/blog/2023/http-conventions-declared-stable/ This has unfortunately not been reflected in OpenTelemetry JS yet, blocked on them making everything backwards compat: open-telemetry/opentelemetry-js#4572 For now we can directly reference `http.request.method`, the replacement to `http.method`. When the OTEL SDK is finally updated to use proper conventions, we can avoid hard coding the string.
1 parent 3eea537 commit 57d6045

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

packages/opentelemetry/src/utils/parseSpanDescription.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ export function parseSpanDescription(span: AbstractSpan): SpanDescription {
3535
const name = spanHasName(span) ? span.name : '<unknown>';
3636

3737
// if http.method exists, this is an http request span
38-
const httpMethod = attributes[SEMATTRS_HTTP_METHOD];
38+
//
39+
// TODO: Referencing `http.request.method` is a temporary workaround until the semantic
40+
// conventions export an attribute key for it.
41+
const httpMethod = attributes['http.request.method'] || attributes[SEMATTRS_HTTP_METHOD];
3942
if (httpMethod) {
4043
return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
4144
}

packages/opentelemetry/test/utils/parseSpanDescription.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('parseSpanDescription', () => {
4141
},
4242
],
4343
[
44-
'works with http method',
44+
'works with deprecated http method',
4545
{
4646
[SEMATTRS_HTTP_METHOD]: 'GET',
4747
},
@@ -53,6 +53,19 @@ describe('parseSpanDescription', () => {
5353
source: 'custom',
5454
},
5555
],
56+
[
57+
'works with http method',
58+
{
59+
'http.request.method': 'GET',
60+
},
61+
'test name',
62+
SpanKind.CLIENT,
63+
{
64+
description: 'test name',
65+
op: 'http.client',
66+
source: 'custom',
67+
},
68+
],
5669
[
5770
'works with db system',
5871
{

0 commit comments

Comments
 (0)