Skip to content

Implementation of a SLF4J MDC Context #455

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

Merged
merged 1 commit into from
Aug 23, 2018
Merged

Implementation of a SLF4J MDC Context #455

merged 1 commit into from
Aug 23, 2018

Conversation

elizarov
Copy link
Contributor

Reworked #403, integrated with #454, see #119

@oshai
Copy link
Contributor

oshai commented Jul 25, 2018

Thanks, I will follow this issue to see when it is integrated.

@elizarov elizarov force-pushed the slf4j-mdc branch 2 times, most recently from a740ded to 19ee038 Compare July 26, 2018 06:20
@elizarov
Copy link
Contributor Author

@abendt A notable different of this PR from the original PR #403 is that when kotlinx-coroutines-slf4j module is in the classpath, then ALL coroutines reset MDC of the current thread to the one that is set in their coroutine context.

Even if you just do runBlocking { ... }, then the code inside will have its MDC reset. You need to explicitly do runBlocking(MDCContext()) { ... } if you want to capture MDC of the current thread and preserve it inside the coroutine.

This is a design decision I'm not entirely sure of, though. It creates side effects to the all code by a simple fact of adding kotlinx-coroutines-slf4j to dependencies.

Another approach would be to only update thread's MDC is the coroutine has MDCContext element in its coroutine context but leave it "as is" for coroutines without MDCContext element. It would mean that runBlocking { .... } preserves MDC of the thread it run in, but then an invocation like withContext(UI) { .... } that is run inside of runBlocking would suddenly "loose" MDC. This decision could also affect the design of PR #454 (cc @qwwdfsad).

@elizarov
Copy link
Contributor Author

@abendt @qwwdfsad It is based on updated #454 thread local API. A usefull side effect of this change is that a plain runBlocking { ... } works as in the original PR #403 -- MDC context on the current thread is kept without changes.

@elizarov elizarov force-pushed the slf4j-mdc branch 2 times, most recently from a83f4aa to 149d9a2 Compare August 21, 2018 16:07
@elizarov elizarov force-pushed the slf4j-mdc branch 2 times, most recently from a83e8cd to 45f055f Compare August 22, 2018 09:51
@qwwdfsad
Copy link
Collaborator

Tests don't match our pattern testFoo.
MDC should be documented better, it's worth to reflect that MDC cannot be implemented dynamically

@elizarov
Copy link
Contributor Author

@qwwdfsad I've updated test named and wrote more detailed docs for MDCContext.

@elizarov elizarov force-pushed the slf4j-mdc branch 2 times, most recently from e7fb0e6 to 08b6ad5 Compare August 23, 2018 11:35
See discussion in PR #403 and issue #119
@elizarov elizarov merged commit 4b0379f into develop Aug 23, 2018
@elizarov elizarov deleted the slf4j-mdc branch August 23, 2018 11:51
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

Successfully merging this pull request may close these issues.

4 participants