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.

[FEATURE REQUEST] Adding Additional Request Scoped Context

See original GitHub issue

Is it possible to add fields to the logged JSON object after the logger is configured?

For example, I’d like to add a userId and organizationId to each log after it’s gone through my authorization guard for the duration of the request.

maybe something inside my auth guard like this.logger.addContext({ userId, orgId});. Then all logs for that request include the additional context.

I thought about extending the injected PinoLogger class, but don’t want to include a RequestScoped injectable essentially everywhere.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
iamoleggacommented, May 15, 2021

From pino docs it looks like there is only one way to add more fields in logger: using child logger (maybe you know some other way?). But this requires replacement of base logger in continuation local storage. Technically looks like this could be possible. But I would prefer addFields or assign instead of addContext because context word is already using for another thing. I’ll convert this question to feature request 👍

1reaction
iamoleggacommented, Sep 29, 2022

@gitSambhal there is single open pinned issue already, you can subscribe and wait or fork and implement

Read more comments on GitHub >

github_iconTop Results From Across the Web

jax rs - Request-scoped context field injections into RESTEasy ...
An instance of SecurityContext can be injected into a class field or method parameter using the @Context annotation.
Read more >
Finally some context: Request scoped state in Go 1.7 - Medium
Request to get a new (shallow copied) Request containing the new context, which you then pass into other handlers without changing the (w...
Read more >
Using the Spring Web Scopes, Part 1 - Manning Publications
A request-scoped bean is an object managed by Spring, for which the framework creates a new instance for every HTTP request. The app...
Read more >
Injection scopes | NestJS - A progressive Node.js framework
For a request-scoped controller, a new instance is created for each inbound request, and garbage-collected when the request has completed processing.
Read more >
Chapter 5. Scopes and contexts
A CDI extension can support the conversation scope for other frameworks as well. The request and application scopes are also active:.
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