nestjs-pino icon indicating copy to clipboard operation
nestjs-pino copied to clipboard

[BUG] nestjs-pino fails to log HTTP requests with global prefix

Open andreymyssak opened this issue 1 year ago • 9 comments

What is the current behavior? After setting a global prefix app.setGlobalPrefix('/api') in main.ts, nestjs-pino unexpectedly stops logging HTTP requests. However, the logger's other functionalities remain operational.

What is the expected behavior? nestjs-pino should consistently log HTTP requests even when a global prefix is applied.

Please provide minimal example repo, not code snippet. Without example repo this issue will be closed.

  1. Clone the repository https://github.com/andreymyssak/nestjs-pino-global-prefix-issue and install dependencies using npm i.
  2. Start the application in development mode with npm run start:dev.
  3. Make a request to localhost:3000/api using a browser or Postman.
  4. Observe that no logs are shown in the terminal for the HTTP request.

Please mention other relevant information such as Node.js version and Operating System. Node.js Version: v18.15.0 Operating System: MacOS Sonoma Version 14.2.1 (23C71)

andreymyssak avatar Feb 11 '24 04:02 andreymyssak

Thanks for reporting, will get back to this as soon as possible

iamolegga avatar Feb 12 '24 09:02 iamolegga

Btw I just tried this on my machine locally, and I can see the request logs just fine. However, on checking OP's sample app I also face the same issue as them. I am using nestjs v10.0.0 but I couldn't solve the issue even on upgrading nestjs-pino and pino-http to the latest versions

keshav-c avatar Jun 09 '24 20:06 keshav-c

I found something interesting during the test. When I clone example repository gave me as an example and tested it, I also face the same issue.

However, if I request to url added another string after prefix like '/api/', '/api/hello', request log works fine.

image

jokj624 avatar Jun 12 '24 16:06 jokj624

Has anyone found a workaround for this problem? I'm running into this problem too, it's frustrating. I'm running nestjs version 10.0.0.

wynadiis23 avatar Jul 30 '24 08:07 wynadiis23

Is there any news about this ? It's really a deal breaker for us :/

abouroubi avatar Aug 18 '24 12:08 abouroubi

The issue is in NestJS, it should be fixed when this PR will land: https://github.com/nestjs/nest/pull/13886

As a workaround you can set the property forRoutes of the LoggerModule to ['*']

abouroubi avatar Aug 19 '24 11:08 abouroubi

The issue is in NestJS, it should be fixed when this PR will land: nestjs/nest#13886

As a workaround you can set the property forRoutes of the LoggerModule to ['*']

Workaround works great for us. Thank you.

The issue is in NestJS, it should be fixed when this PR will land: nestjs/nest#13886

As a workaround you can set the property forRoutes of the LoggerModule to ['*']

Thanks for this workaround saved us a huge headache as we have realised newer services we've built had absolutely no logging and we also determined that the change to the middleware-module was what broke all of our logging.

The PR needs to be merged ASAP as this has broken critical services within our business

TisRyno avatar Aug 19 '24 14:08 TisRyno

@andreymyssak try app.setGlobalPrefix('api') (without the /). I have app.setGlobalPrefix('v2') and logging works fine for me.

aqeelat avatar Sep 09 '24 13:09 aqeelat