Skip to content

Commit a457d94

Browse files
authored
fix(instrumentation-http): include query params in http.target (#3646)
* fix: set http.target as path (like spec) and not pathname * fix: set http.target as path (like spec) and not pathname * fix: set http.target as path (like spec) and not pathname
1 parent 74ca04f commit a457d94

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/
2323
### :bug: (Bug Fix)
2424

2525
* 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
26+
* fix(instrumentation-http): include query params in http.target [#3646](https://github.com/open-telemetry/opentelemetry-js/pull/3646) @kobi-co
2627

2728
### :books: (Refine Doc)
2829

experimental/packages/opentelemetry-instrumentation-http/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ export const getIncomingRequestAttributes = (
484484
}
485485

486486
if (requestUrl) {
487-
attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.pathname || '/';
487+
attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.path || '/';
488488
}
489489

490490
if (userAgent !== undefined) {

experimental/packages/opentelemetry-instrumentation-http/test/functionals/utils.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,23 @@ describe('Utility', () => {
503503
});
504504
assert.strictEqual(attributes[SemanticAttributes.HTTP_ROUTE], undefined);
505505
});
506+
507+
it('should set http.target as path in http span attributes', () => {
508+
const request = {
509+
url: 'http://hostname/user/?q=val',
510+
method: 'GET',
511+
} as IncomingMessage;
512+
request.headers = {
513+
'user-agent': 'chrome',
514+
};
515+
const attributes = utils.getIncomingRequestAttributes(request, {
516+
component: 'http',
517+
});
518+
assert.strictEqual(
519+
attributes[SemanticAttributes.HTTP_TARGET],
520+
'/user/?q=val'
521+
);
522+
});
506523
});
507524

508525
describe('headers to span attributes capture', () => {

0 commit comments

Comments
 (0)