diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 7f28f48e95d..dba8a3e71f4 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -78,9 +78,13 @@ See the <> 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]) diff --git a/lib/instrumentation/express-utils.js b/lib/instrumentation/express-utils.js index 0a2edb65208..82595aa64fb 100644 --- a/lib/instrumentation/express-utils.js +++ b/lib/instrumentation/express-utils.js @@ -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) { diff --git a/test/instrumentation/express-utils.test.js b/test/instrumentation/express-utils.test.js index 3917d132845..8ec19e4d90b 100644 --- a/test/instrumentation/express-utils.test.js +++ b/test/instrumentation/express-utils.test.js @@ -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, }; }