diff --git a/CHANGELOG.md b/CHANGELOG.md index 607cb9544d..a5014e7737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :bug: (Bug Fix) * fix(core): added falsy check to make otel core work with browser where webpack config had process as false or null [#3613](https://github.com/open-telemetry/opentelemetry-js/issues/3613) @ravindra-dyte +* fix(instrumentation-http): include query params in http.target [#3646](https://github.com/open-telemetry/opentelemetry-js/pull/3646) @kobi-co ### :books: (Refine Doc) diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts b/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts index 7801a7626c..a563e29471 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/utils.ts @@ -484,7 +484,7 @@ export const getIncomingRequestAttributes = ( } if (requestUrl) { - attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.pathname || '/'; + attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.path || '/'; } if (userAgent !== undefined) { 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 700498cfb6..35b3c1ab5b 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts @@ -503,6 +503,23 @@ describe('Utility', () => { }); assert.strictEqual(attributes[SemanticAttributes.HTTP_ROUTE], undefined); }); + + it('should set http.target as path in http span attributes', () => { + const request = { + url: 'http://hostname/user/?q=val', + method: 'GET', + } as IncomingMessage; + request.headers = { + 'user-agent': 'chrome', + }; + const attributes = utils.getIncomingRequestAttributes(request, { + component: 'http', + }); + assert.strictEqual( + attributes[SemanticAttributes.HTTP_TARGET], + '/user/?q=val' + ); + }); }); describe('headers to span attributes capture', () => {