elastic / ecs-logging-nodejs

https://www.elastic.co/guide/en/ecs-logging/nodejs/master/intro.html
Apache License 2.0
68 stars 39 forks source link

url is used instead of originalUrl in http-foramtters helper functions #114

Closed blue-int closed 1 year ago

blue-int commented 2 years ago

I used morgan with ecsFormat to record http requests in elasticsearch, but the url field is not accurate.

app.use("/base", router);
router.get("/:service", (req, res, next) => {...})

In this example, req.url is /:service and req.originalUrl is /base/:service, because req.url is changed when the router is mounted to /base. formatHttpRequest helper function uses req.url when formatting url, so that baseUrl is ignored. It should use req.originalUrl instead of req.url.

marcin-wlodarczyk commented 2 years ago

Any progress on this? I have the same problem...

trentm commented 1 year ago

Thank you for the issue and my apologies for the delay.

https://expressjs.com/en/4x/api.html#req.originalUrl When using Express, this library needs to prefer req.originalUrl because Express overwrites req.url during its routing.