slf4j MDC with java.lang.LinkageError, within the transaction created by external plugin and log correlation enabled
See original GitHub issueUsing agent 1.27.0, and enable log correlation
Within the transaction created by external plugin, the application will throw java.lang.LinkageError, the stack trace is :
java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticMDCBinder.getMDCA()Lorg/slf4j/spi/MDCAdapter;" the class loader co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader @64d6d42b (instance of co.elastic.apm.agent.bci.classloading.IndyPluginClassLoader, child of co.elastic.apm.agent.bci.classloading.DiscriminatingMultiParentClassLoader @737bfc4e co.elastic.apm.agent.bci.classloading.DiscriminatingMultiParentClassLoader) of the current class, org/slf4j/MDC, and the class loader co.elastic.apm.agent.premain.ShadedClassLoader @32709393 (instance of co.elastic.apm.agent.premain.ShadedClassLoader, child of co.elastic.apm.agent.premain.ShadedClassLoader @35d176f7 co.elastic.apm.agent.premain.ShadedClassLoader) for the method's defining class, org/slf4j/impl/StaticMDCBinder, have different Class objects for the type org/slf4j/spi/MDCAdapter used in the signature
at org.slf4j.MDC.bwCompatibleGetMDCAdapterFromBinder(MDC.java:102)
at org.slf4j.MDC.<clinit>(MDC.java:108)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1044)
at java.base/java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue(DirectMethodHandle.java:357)
at java.base/java.lang.invoke.DirectMethodHandle$EnsureInitialized.computeValue(DirectMethodHandle.java:354)
at java.base/java.lang.ClassValue.getFromHashMap(ClassValue.java:228)
at java.base/java.lang.ClassValue.getFromBackup(ClassValue.java:210)
at java.base/java.lang.ClassValue.get(ClassValue.java:116)
at java.base/java.lang.invoke.DirectMethodHandle.checkInitialized(DirectMethodHandle.java:378)
at java.base/java.lang.invoke.DirectMethodHandle.ensureInitialized(DirectMethodHandle.java:368)
at java.base/java.lang.invoke.DirectMethodHandle.internalMemberNameEnsureInit(DirectMethodHandle.java:318)
at co.elastic.apm.agent.mdc.MdcActivationListener.before(MdcActivationListener.java:189)
at co.elastic.apm.agent.mdc.MdcActivationListener.beforeActivate(MdcActivationListener.java:173)
at co.elastic.apm.agent.impl.ElasticApmTracer.activate(ElasticApmTracer.java:690)
at co.elastic.apm.agent.impl.transaction.AbstractSpan.activate(AbstractSpan.java:495)
at co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$ActivateInstrumentation$AdviceClass.activate(AbstractSpanInstrumentation.java:392)
at co.elastic.apm.api.AbstractSpanImpl.activate(AbstractSpanImpl.java:156)
According to the stack trace above, i guess:
1、the transaction was created by elastic apm agent api in external plugin , so the application classloader of the trace context will be IndyPluginClassLoader
2、As the transaction activating, the MdcActivationListener will be called,and it will try to load slf4j MDC class, using IndyPluginClassLoader, but some oher class has already been loaded by ShadedClassLoader, and throw java.lang.LinkageError
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Improved Java Logging with Mapped Diagnostic Context (MDC)
In this tutorial, we will explore the use of Mapped Diagnostic Context (MDC) to improve the application logging. Mapped Diagnostic Context ...
Read more >Java Agent version 1.x | APM Java Agent Reference [master]
Log correlation now works based on bytecode instrumentation rather than ActivationListener that directly updates the MDC; Merging the different instrumentations ...
Read more >How to retain slf4j MDC logging context in CompletableFuture?
When all do we get new instances of CompletableFuture from outside this class? → We need to return a MDC aware version of...
Read more >Log Correlation - TechDocs
The Log Correlation Java Agent extension increases visibility into application performance issues by correlating your application server ...
Read more >Spring Cloud Sleuth
Once you create a span, you must stop it at some point in the future. ... Adds trace and span IDs to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are right, version 1.26.2 does not produce those errors
@CoderLan0668 you are welcome to try out the proposed fix build. Your feedback would be much appreciated.