diff --git a/src/express-middleware.js b/src/express-middleware.js index 86aad69..520de92 100644 --- a/src/express-middleware.js +++ b/src/express-middleware.js @@ -51,7 +51,7 @@ class ExpressMiddleware { route = req.originalUrl.split('?')[0]; } else { const splittedRoute = route.split('/'); - const splittedUrl = req.originalUrl.split('/'); + const splittedUrl = req.originalUrl.split('?')[0].split('/'); const routeIndex = splittedUrl.length - splittedRoute.length + 1; const baseUrl = splittedUrl.slice(0, routeIndex).join('/'); @@ -69,12 +69,12 @@ class ExpressMiddleware { route = route.replace(req.params[paramName], ':' + paramName); }); } - + // this condition will evaluate to true only in // express framework and no route was found for the request. if we log this metrics // we'll risk in a memory leak since the route is not a pattern but a hardcoded string. if (!route || route === '') { - // if (!req.route && res && res.statusCode === 404) { + // if (!req.route && res && res.statusCode === 404) { route = 'N/A'; } diff --git a/test/integration-tests/express/middleware-test.js b/test/integration-tests/express/middleware-test.js index 6c7122e..6ae69be 100644 --- a/test/integration-tests/express/middleware-test.js +++ b/test/integration-tests/express/middleware-test.js @@ -307,7 +307,7 @@ describe('when using express framework', () => { }); }); }); - describe('when calling a GET endpoint with query parmas', () => { + describe('when calling a GET endpoint with query params', () => { before(() => { return supertest(app) .get('/v2?test=test') @@ -323,6 +323,22 @@ describe('when using express framework', () => { }); }); }); + describe('when calling a GET endpoint with query params with special character /', () => { + before(() => { + return supertest(app) + .get('/checkout?test=test/test1') + .expect(200) + .then((res) => { }); + }); + it('should add it to the histogram', () => { + return supertest(app) + .get('/metrics') + .expect(200) + .then((res) => { + expect(res.text).to.contain('http_request_duration_seconds_bucket{le="+Inf",method="GET",route="/checkout",code="200"} 1'); + }); + }); + }); }); describe('sub-sub app with error handler in the sub app', function () { describe('when calling a GET endpoint with path params and sub router', () => {