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

Logback instrumentation broken with with logback-classic 1.4.x #1251

Closed
nvollmar opened this issue Jan 18, 2023 · 6 comments
Closed

Logback instrumentation broken with with logback-classic 1.4.x #1251

nvollmar opened this issue Jan 18, 2023 · 6 comments

Comments

@nvollmar
Copy link
Contributor

The new implementation which addressed #1212 does not properly work.
I've extended an internal test and there is about 50/50 chance that the mdc values are attached to the log or not. On deployed systems we see a similar behaviour.

The new LogbackMDCAdapter implementation uses two thread locals to store the MDC map, and getPropertyMap is only one entry point for it. There are also get/getKeys and put to access those properties.
I'm not yet sure where it exactly fails, but it seems to at least work when the property map is not yet set:

appendContext:66, ContextToMdcPropertyMapAppender$ (jaso.commons.kamon.instrumentation)
appendContext:-1, ContextToMdcPropertyMapAppender (jaso.commons.kamon.instrumentation)
getPropertyMap:146, LogbackMDCAdapter (ch.qos.logback.classic.util)
getMDCPropertyMap:410, LoggingEvent (ch.qos.logback.classic.spi)
prepareForDeferredProcessing:256, LoggingEvent (ch.qos.logback.classic.spi)
preprocess:45, AsyncAppender (ch.qos.logback.classic)
preprocess:29, AsyncAppender (ch.qos.logback.classic)
append:165, AsyncAppenderBase (ch.qos.logback.core)
doAppend:85, UnsynchronizedAppenderBase (ch.qos.logback.core)
appendLoopOnAppenders:51, AppenderAttachableImpl (ch.qos.logback.core.spi)
appendLoopOnAppenders:272, Logger (ch.qos.logback.classic)
callAppenders:259, Logger (ch.qos.logback.classic)
buildLoggingEventAndAppend:426, Logger (ch.qos.logback.classic)
filterAndLog_2:419, Logger (ch.qos.logback.classic)
error:535, Logger (ch.qos.logback.classic)
$anonfun$route$2:274, RemoteHTTPServerStub (jaso.commons.akka.http)
....

(This is a stack trace where it worked, I copied over the latest implementation to play around)

@nvollmar nvollmar changed the title Logback instrumentation broken with 1.4.3 Logback instrumentation broken with with logback-classic 1.4.3 Jan 18, 2023
@nvollmar nvollmar changed the title Logback instrumentation broken with with logback-classic 1.4.3 Logback instrumentation broken with with logback-classic 1.4.x Jan 18, 2023
@nvollmar
Copy link
Contributor Author

@ivantopo I've reverted back to the original intercept implementation but switched interception to LoggingEvent.getMDCPropertyMap instead of LogbackMDCAdapter.getPropertyMap:

  onType("ch.qos.logback.classic.spi.LoggingEvent")
    .intercept(method("getMDCPropertyMap"), GetPropertyMapMethodInterceptor)

This seems to work reliably on both Logback 1.2.10 and 1.4.5

@ivantopo
Copy link
Contributor

Hey @nvollmar, thanks so much for bringing this up! Just to be sure on something, did you have this issue even when using the setting included on #1236? That would be:

kanela.modules.play-framework.order = 3

There were some random problems due to initialization order, but those should have been fixed after adding this setting.

@ivantopo
Copy link
Contributor

@nvollmar see this comment too: #1234 (comment)

@nvollmar
Copy link
Contributor Author

@ivantopo We don’t use play, we build directly on plain Akka.

@ivantopo
Copy link
Contributor

Thanks for sharing @nvollmarl, I gave it a try on a few applications locally and worked as expected 💪

@ivantopo
Copy link
Contributor

Fixed in #1252

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

2 participants