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

JDBC Driver instrumentation results in an AbstractMethodError if the Connection is proxied #5032

Closed
ryanrupp opened this issue Jan 7, 2022 · 4 comments
Labels
bug Something isn't working

Comments

@ryanrupp
Copy link

ryanrupp commented Jan 7, 2022

Describe the bug
See this repo branch to reproduce the issue (can ignore the Jetty stuff, the code to cause the problem is in ReproduceReflectionProxyIssue). The issue manifests if you:

  1. Have something like Driver#connect that is instrumented.
  2. You proxy the resulting Connection

I narrowed this down to the issue starting with the change in #4390.

As a workaround I can use otel.javaagent.exclude-classes and exclude the WrappingDriver from instrumentation.

Steps to reproduce
See linked repository from description.

What did you expect to see?
No exception during instrumentation

What did you see instead?
AbstractMethodError during instrumentation.

Java 11 error example:

[main] DEBUG io.opentelemetry.javaagent.bootstrap.ExceptionLogger - Failed to handle exception in instrumentation for example.ReproduceReflectionProxyIssue$WrappingDriver on jdk.internal.loader.ClassLoaders$AppClassLoader@2c13da15
java.lang.AbstractMethodError: Receiver class com.sun.proxy.$Proxy44 does not define or inherit an implementation of the resolved method abstract __set__opentelemetryVirtualField$java$sql$Connection$io$opentelemetry$javaagent$shaded$instrumentation$jdbc$internal$DbInfo(Ljava/lang/Object;)V of interface io.opentelemetry.javaagent.bootstrap.field.VirtualFieldAccessor$java$sql$Connection$io$opentelemetry$javaagent$shaded$instrumentation$jdbc$internal$DbInfo.
    at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$java$sql$Connection$io$opentelemetry$javaagent$shaded$instrumentation$jdbc$internal$DbInfo.realPut(VirtualFieldImplementationsGenerator.java)
    at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$java$sql$Connection$io$opentelemetry$javaagent$shaded$instrumentation$jdbc$internal$DbInfo.set(VirtualFieldImplementationsGenerator.java:282)
    at example.ReproduceReflectionProxyIssue$WrappingDriver.connect(ReproduceReflectionProxyIssue.java:49)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
    at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
    at example.ReproduceReflectionProxyIssue.setup(ReproduceReflectionProxyIssue.java:23)
    at example.ApplicationMain.main(ApplicationMain.java:47)

Java 8 error example (slightly different logging):

[main] DEBUG io.opentelemetry.javaagent.bootstrap.ExceptionLogger - Failed to handle exception in instrumentation for example.ReproduceReflectionProxyIssue$WrappingDriver on sun.misc.Launcher$AppClassLoader@18b4aac2
java.lang.AbstractMethodError
at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$java$sql$Connection$io$opentelemetry$javaagent$shaded$instrumentation$jdbc$internal$DbInfo.realPut(VirtualFieldImplementationsGenerator.java)
at io.opentelemetry.javaagent.bootstrap.field.VirtualFieldImpl$java$sql$Connection$io$opentelemetry$javaagent$shaded$instrumentation$jdbc$internal$DbInfo.set(VirtualFieldImplementationsGenerator.java:282)
at example.ReproduceReflectionProxyIssue$WrappingDriver.connect(ReproduceReflectionProxyIssue.java:49)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at example.ReproduceReflectionProxyIssue.setup(ReproduceReflectionProxyIssue.java:23)
at example.ApplicationMain.main(ApplicationMain.java:47)

What version are you using?
1.9.1 = exception occurs
1.7.0 = exception occurs
1.6.2 = no exception

Environment
Docker Linux + OpenJDK 8 or 11

@ryanrupp ryanrupp added the bug Something isn't working label Jan 7, 2022
@ryanrupp
Copy link
Author

ryanrupp commented Jan 7, 2022

Maybe relates in a way to #5012

@ryanrupp
Copy link
Author

ryanrupp commented Jan 7, 2022

The driver instrumentation here could probably check if the resulting Connection is a proxy and not try to store any data around this but I'm not sure if:

  1. That would break other things
  2. Solves the immediate need but maybe similar issue is else where

@ryanrupp ryanrupp changed the title JDBC instrumentation results in an AbstractMethodError if the Connection is proxied JDBC Driver instrumentation results in an AbstractMethodError if the Connection is proxied Jan 7, 2022
@laurit
Copy link
Contributor

laurit commented Jan 7, 2022

@ryanrupp I wasn't able to reproduce this with current snapshot could you verify whether the issue is still present with the latest snapshot from https://oss.sonatype.org/content/repositories/snapshots/io/opentelemetry/javaagent/opentelemetry-javaagent/1.10.0-SNAPSHOT/

@ryanrupp
Copy link
Author

ryanrupp commented Jan 7, 2022

@laurit Ah I didn't actually test current main/snapshots, just the released versions. This does appear to be fixed in opentelemetry-javaagent-1.10.0-20211129.215152-6.jar which means this was fixed by #4722

So I'll probably just exclude the problematic wrapper class to be able to upgrade to 1.9.x then will take 1.10 later when it's released.

Thanks!

@ryanrupp ryanrupp closed this as completed Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants