opentelemetry-android icon indicating copy to clipboard operation
opentelemetry-android copied to clipboard

Classloader fails to load OpenTelemetryRum if built in debug with desugaring on

Open bidetofevil opened this issue 10 months ago • 10 comments

Ran into an issue that manifests in an Android build environment, with a trigger that is in the semconv module, but the ultimate root cause is likely in the Android toolchain (my bet is D8/AGP). But I figure I'd start with an issue here first, then figure out how to best workaround this for this project and then fix the issue upstream

Basically, desugaring in debug (or more specifically, without R8 minification) causes issues in the modified classes whereby the non-desugared version of a static interface default method was being accessed, but isn't actually present in the dex file.

This issue manifests when a static AttributeKey in the module that is instantiated with a static interface default method is accessed (e.g. ResourceAttributes.SERVICE_NAME). For some reason, that reference is still trying to access the non-desugared version (whether you're running in an Android runtime version that needs desugaring or not), which doesn't exist in the dex.

If in our own module's code, we call the same method, even in the same static member instantiation context, the call works. So the issue is likely not with the modification of the desugared method, but rather in how the callsite was or wasn't modified. Or there's some dangling reference that applies in one case but not the other. Or some dumb race condition. Who knows.

I pushed a repro in a branch that uses an instrumentation test to cause the problem, but I can do this via a test app as well by turning on desugaring and building in debug.

This issue goes away when we bump the minSdkVersion to 24 as that means desguaring is not necessary for Java 8 APIs, but it will continue to be an issue if our min is 21.

We can discuss how we want to address this - or not. Release builds aren't affected, so this will mainly be a PITA for devs and no one else.

bidetofevil avatar Apr 06 '24 22:04 bidetofevil