kamon-io / Kamon

Distributed Tracing, Metrics and Context Propagation for applications running on the JVM
https://kamon.io
Other
1.41k stars 327 forks source link

Spring instrumentation fails with spring-boot 3 / spring 6 #1283

Open lbuffler opened 1 year ago

lbuffler commented 1 year ago

Spring framework version 6 (used by Spring Boot 3) changed the servlet API, moving away from javax.servlet and started using jakarta.servlet. This causes the Kamon instrumentation to fail at startup with the following exception (Kamon version 2.6.1):

Error => org.springframework.web.servlet.DispatcherServlet with message Cannot assign jakarta.servlet.http.HttpServletRequest request to interface javax.servlet.http.HttpServletRequest. Class loader: jdk.internal.loader.ClassLoaders$AppClassLoader@293a5bf6: java.lang.IllegalStateException: Cannot assign jakarta.servlet.http.HttpServletRequest request to interface javax.servlet.http.HttpServletRequest
at kanela.agent.libs.net.bytebuddy.asm.Advice$OffsetMapping$ForArgument.resolve(Advice.java:1581)
at kanela.agent.libs.net.bytebuddy.asm.Advice$OffsetMapping$ForArgument$Unresolved.resolve(Advice.java:1689)
at kanela.agent.libs.net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$ForMethodEnter.doApply(Advice.java:8684)
at kanela.agent.libs.net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$ForMethodEnter.apply(Advice.java:8642)
at kanela.agent.libs.net.bytebuddy.asm.Advice$Dispatcher$Inlining$Resolved$AdviceMethodInliner.visitMethod(Advice.java:8332)

This would be trivial to fix (just change the package name), but then it would break existing apps. Maybe there's a way to detect which version of the servlet API is installed and configure the instrumentation accordingly?

hughsimpson commented 11 months ago

Yes we can do this, the instrumentation advice to configure with a new package name can just be added alongside. I don't think there's anything that makes this a hard problem given that.

iosyyy commented 2 weeks ago

how to fix it or disable it