Skip to content

Commit

Permalink
fix(instrumentation-http): include query params in http.target (#3646)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kobi-co authored Mar 1, 2023
1 parent 74ca04f commit a457d94
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export const getIncomingRequestAttributes = (
}

if (requestUrl) {
attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.pathname || '/';
attributes[SemanticAttributes.HTTP_TARGET] = requestUrl.path || '/';
}

if (userAgent !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit a457d94

Please sign in to comment.