apm-agent-java: slf4j MDC with java.lang.LinkageError, within the transaction created by external plugin and log correlation enabled

Using 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

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (15 by maintainers)

Most upvoted comments

@CoderLan0668, @tobiasstadler, @wolframhaussig - If you do get the chance to try them out, please provide your feedback. Thanks!

You are right, version 1.26.2 does not produce those errors