From 03f87abd3f459d78f5de02cdc6137e766be527b9 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 23 Apr 2024 12:29:18 -0400 Subject: [PATCH] feat(opentelemetry): Support new http method attribute --- .../src/utils/parseSpanDescription.ts | 5 ++++- .../test/utils/parseSpanDescription.test.ts | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/opentelemetry/src/utils/parseSpanDescription.ts b/packages/opentelemetry/src/utils/parseSpanDescription.ts index 988ca1f3b5ee..9888e8b5b0dd 100644 --- a/packages/opentelemetry/src/utils/parseSpanDescription.ts +++ b/packages/opentelemetry/src/utils/parseSpanDescription.ts @@ -35,7 +35,10 @@ export function parseSpanDescription(span: AbstractSpan): SpanDescription { const name = spanHasName(span) ? span.name : ''; // if http.method exists, this is an http request span - const httpMethod = attributes[SEMATTRS_HTTP_METHOD]; + // + // TODO: Referencing `http.request.method` is a temporary workaround until the semantic + // conventions export an attribute key for it. + const httpMethod = attributes['http.request.method'] || attributes[SEMATTRS_HTTP_METHOD]; if (httpMethod) { return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod); } diff --git a/packages/opentelemetry/test/utils/parseSpanDescription.test.ts b/packages/opentelemetry/test/utils/parseSpanDescription.test.ts index 3e25356d1025..1e7178871ff1 100644 --- a/packages/opentelemetry/test/utils/parseSpanDescription.test.ts +++ b/packages/opentelemetry/test/utils/parseSpanDescription.test.ts @@ -41,7 +41,7 @@ describe('parseSpanDescription', () => { }, ], [ - 'works with http method', + 'works with deprecated http method', { [SEMATTRS_HTTP_METHOD]: 'GET', }, @@ -53,6 +53,19 @@ describe('parseSpanDescription', () => { source: 'custom', }, ], + [ + 'works with http method', + { + 'http.request.method': 'GET', + }, + 'test name', + SpanKind.CLIENT, + { + description: 'test name', + op: 'http.client', + source: 'custom', + }, + ], [ 'works with db system', {