Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: capture route from base on express app.use #3631

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ See the <<upgrade-to-v4>> guide.
* Add support for `@aws-sdk/client-dynamodb`, one of the AWS SDK v3 clients.
({issues}2958[#2958])

[float]
===== Bug fixes
* Add support for `@aws-sdk/client-sns`, one of the AWS SDK v3 clients.
({issues}2956[#2956])

* The problem of route name not being captured in Express.Use direct use in middleware has been resolved.

* Add support for `@aws-sdk/client-sqs`, one of the AWS SDK v3 clients.
({issues}2957[#2957])

Expand Down
2 changes: 2 additions & 0 deletions lib/instrumentation/express-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function getPathFromRequest(req, useBase, usePathAsTransactionName) {
return path ? join([path, route]) : route;
} else if (path && (path !== '/' || useBase)) {
return path;
} else if (req.baseUrl && req.baseUrl !== '/') {
return req.baseUrl;
}

if (usePathAsTransactionName) {
Expand Down
15 changes: 14 additions & 1 deletion test/instrumentation/express-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,26 @@ test('#getPathFromRequest', function (t) {
t.equals(path, '/foo/bar');
t.end();
});
t.test('should return path for express.use base urls as path ', function (t) {
const req = createRequest(
'https://test.com/foo/bar?query=value#hash',
'example.com',
{
baseUrl: '/foo/bar',
},
);
const path = getPathFromRequest(req, false, false);
t.equals(path, '/foo/bar');
t.end();
});
});

function createRequest(url, host = 'example.com') {
function createRequest(url, host = 'example.com', additionalRequestItems) {
return {
url,
headers: {
host,
},
...additionalRequestItems,
};
}