Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ See the <<upgrade-to-v4>> guide.

[float]
===== Bug fixes
* The problem of route name not being captured in Express.Use direct use in middleware has been resolved.

[float]
===== Chores
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,
};
}