From 5e7cd471d71b50569105053b9d2e61617f41e364 Mon Sep 17 00:00:00 2001 From: Mustafain Ali Khan Date: Thu, 23 Sep 2021 14:29:30 -0400 Subject: [PATCH] fix: remove setting http.route in http span attributes --- .../src/utils.ts | 1 - .../test/functionals/utils.test.ts | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts b/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts index a24ff6f12a..d7fc6efc9b 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts @@ -453,7 +453,6 @@ export const getIncomingRequestAttributes = ( } if (requestUrl) { - attributes[SemanticAttributes.HTTP_ROUTE] = requestUrl.pathname || '/'; attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.pathname || '/'; } diff --git a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts index d530fac61c..3192168829 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts @@ -465,4 +465,19 @@ describe('Utility', () => { verifyValueInAttributes(attributes, undefined, 1200); }); }); + + describe('getIncomingRequestAttributes()', () => { + it('should not set http.route in http span attributes', () => { + const request = { + url: 'http://hostname/user/:id', + method: 'GET' + } as IncomingMessage; + request.headers = { + 'user-agent': 'chrome', + 'x-forwarded-for': ', , ' + } + const attributes = utils.getIncomingRequestAttributes(request, { component: 'http'}) + assert.strictEqual(attributes[SemanticAttributes.HTTP_ROUTE], undefined) + }); + }) });