question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] PinoLogger: unable to assign extra fields out of request scope // when trying to assign from middleware

See original GitHub issue

[x] I’ve read the docs of nestjs-pino

[x] I’ve read the docs of pino

[x] I couldn’t find the same open issue of nestjs-pino

What is the current behavior? When trying to use logger.assign you receive the error “PinoLogger: unable to assign extra fields out of request scope”

{"level":30,"time":1657116598814,"pid":908,"hostname":"ascherer-pc","context":"NestFactory","msg":"Starting Nest application..."}
{"level":30,"time":1657116598815,"pid":908,"hostname":"ascherer-pc","context":"InstanceLoader","msg":"AppModule dependencies initialized"}    
{"level":30,"time":1657116598815,"pid":908,"hostname":"ascherer-pc","context":"InstanceLoader","msg":"LoggerModule dependencies initialized"} 
{"level":30,"time":1657116598815,"pid":908,"hostname":"ascherer-pc","context":"RoutesResolver","msg":"AppController {/}:"}
{"level":30,"time":1657116598815,"pid":908,"hostname":"ascherer-pc","context":"RouterExplorer","msg":"Mapped {/, GET} route"}
{"level":30,"time":1657116598815,"pid":908,"hostname":"ascherer-pc","context":"NestApplication","msg":"Nest application successfully started"}
{"level":50,"time":1657116608244,"pid":908,"hostname":"ascherer-pc","context":"ExceptionsHandler","err":{"type":"Error","message":"PinoLogger: unable to assign extra fields out of request scope","stack":"Error: PinoLogger: unable to assign extra fields out of request scope\n    at PinoLogger.assign (C:\\dev\\github.com\\nestjs-pino-request-scope-examp
le\\node_modules\\nestjs-pino\\PinoLogger.js:104:19)\n    at LoggerContextMiddleware.use (C:\\dev\\github.com\\nestjs-pino-request-scope-example\\src\\logger-context.middleware.ts:12:17)\n    at C:\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\@nestjs\\core\\router\\router-proxy.js:9:23\n    at Layer.handle [as handle_request] (C:
\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\express\\lib\\router\\layer.js:95:5)\n    at trim_prefix (C:\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\express\\lib\\router\\index.js:328:13)\n    at C:\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\express\\lib\\router\\index.js:286:9\n  
  at param (C:\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\express\\lib\\router\\index.js:365:14)\n    at param (C:\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\express\\lib\\router\\index.js:376:14)\n    at Function.process_params (C:\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\expre
ss\\lib\\router\\index.js:421:3)\n    at next (C:\\dev\\github.com\\nestjs-pino-request-scope-example\\node_modules\\express\\lib\\router\\index.js:280:10)"},"msg":"PinoLogger: unable to assign extra fields out of request scope"}

What is the expected behavior? The specified value get’s assigned for the logs of the current request

Please provide minimal example repo. Without it this issue will be closed https://github.com/schealex/nestjs-pino-request-scope-example

Please mention other relevant information such as Node.js version and Operating System. this is the bug report follow up for my question https://github.com/iamolegga/nestjs-pino/issues/1020

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
CatsMiaowcommented, Jul 16, 2022
1reaction
schealexcommented, Jul 12, 2022

No worries that was already very helpful!

I’ve created two new branches on my test repo:

hope this can help you resolve this. At least for our case i can go the interceptor route now 😃 thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[FEATURE REQUEST] Adding Additional Request Scoped ...
I am getting PinoLogger: unable to assign extra fields out of request scope with Pubsub.
Read more >
How to inject a request scoped provider at NestJS controller?
Injecting it at the constructor will make the controller be recreated on each request, so surely that's not the way (is it?). I...
Read more >
nestjs-pino - npm
Platform agnostic logger for NestJS based on Pino with REQUEST CONTEXT IN EVERY LOG ... get() { // assign extra fields in one...
Read more >
Logging - Fastify
As Fastify is focused on performance, it uses pino as its logger, with the default log level, when enabled, set to 'info' ....
Read more >
Logger | NestJS - A progressive Node.js framework
To disable logging, set the logger property to false in the (optional) Nest application options object passed as the second argument to the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found