Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapped Diagnostic Context ? #25

Open
thiloplanz opened this issue Jun 12, 2019 · 7 comments
Open

Mapped Diagnostic Context ? #25

thiloplanz opened this issue Jun 12, 2019 · 7 comments

Comments

@thiloplanz
Copy link

Are there any plans to integrate MDC?

Because of the "classic" MDC implementation using thread locals not working very well in thread-shifting environments like ZIO (or pretty much anything else in Scalaland), having this enabled out of the box (i.e. without the user having to manually mess with fiber-locals or such) would be the killer feature for this library.

@wpoosanguansit
Copy link

+1

I was about to ask on how to log the trace on code that forks. I hope there is an easier way to do that with the library.

@NeQuissimus
Copy link
Owner

Any PRs are more than welcome. I am not super familiar with MDC but I bet it could be integrated with the tracing capabilities in ZIO

@wpoosanguansit
Copy link

@NeQuissimus Could you show how can we log or trace code that forks? Thanks for your help.

@nigredo-tori
Copy link

SLF4J 2.0 adds a new facility for attaching key-value pairs to logging events, together with LoggingEventBuilders. In the long term, this should fit this library much better than abusing thread-local MDC APIs.

@NeQuissimus
Copy link
Owner

@nigredo-tori Interesting, I would love to see an example of that work. PRs are always welcome, too :)

@thiloplanz
Copy link
Author

@nigredo-tori Not sure if LoggingEventBuilders are useful here.

They seem to provide an alternative way to prepare/format a single log message, whereas the main use-case for MDC is to be able to split attaching context from the (usually multiple) places that produce logs.

A common example is attaching a "request id" at the top of your application that gets then included in the dozens of log messages output all over your codebase (without those places having to know about it).

It may be theoretically possible to pass around a LoggingEventBuilder, but those already fix the log level and the logger name at creation time before you can even set a key-value pair, so that neither could be changed anymore. It would also force all user code to stop using the familiar "old" API (log.debug("something")) if they want to pick up the context values.

@thiloplanz
Copy link
Author

There is now a proposal for an "official" ZIO Logging interface with pluggable backends (one of which could be this one, I suppose), and they are discussing providing a context object there (which would presumably be implemented using FiberRef and be used for Mapped Diagnostic Context such as correlation ids).

zio/zio-logging#1 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants