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

ClassCastException in OpenTelemetrySdk.getTracerProvider() #1305

Closed
fmhwong opened this issue Jun 4, 2020 · 17 comments
Closed

ClassCastException in OpenTelemetrySdk.getTracerProvider() #1305

fmhwong opened this issue Jun 4, 2020 · 17 comments
Labels

Comments

@fmhwong
Copy link

fmhwong commented Jun 4, 2020

Describe the bug
ClassCastException was thrown when running this code snippet

        ManagedChannel jaegerChannel = ManagedChannelBuilder.forAddress(ip, port).usePlaintext().build();
        this.jaegerExporter = JaegerGrpcSpanExporter.newBuilder().setServiceName("example").setChannel(jaegerChannel).setDeadlineMs(30000).build();
        OpenTelemetrySdk.getTracerProvider().addSpanProcessor(SimpleSpanProcessor.newBuilder(this.jaegerExporter).build());

Exception:

Stack Dump = java.lang.ClassCastException: io.opentelemetry.trace.DefaultTracerProvider incompatible with io.opentelemetry.internal.Obfuscated
	at io.opentelemetry.sdk.OpenTelemetrySdk.getTracerProvider(OpenTelemetrySdk.java:44)
	at ...

Steps to reproduce
The above code was fine when running in a Java main program. When it was running inside an application server, the ClassCastException was encountered.

What did you expect to see?
No exception is thrown.

What did you see instead?
ClassCastException was thrown.

What version and what artifacts are you using?
Artifacts: (e.g., opentelemetry-api, opentelemetry-sdk, which exporters, etc)
Version: (e.g., v0.4.0, 1eb551b, etc)
How did you reference these artifacts? (excerpt from your build.gradle, pom.xml, etc)

opentelemetry-api and sdk 0.5.0-SNAPSHOT

Environment
Compiler: (e.g., "AdoptOpenJDK 11.0.6")
OS: (e.g., "Ubuntu 20.04")
Runtime (if different from JDK above): (e.g., "Oracle JRE 8u251")
OS (if different from OS compiled on): (e.g., "Windows Server 2019")

java -version
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.17.0, JRE 11 Mac OS X amd64-64-Bit Compressed References 20191031_374 (JIT enabled, AOT enabled)
OpenJ9   - 77c1cf708
OMR      - 20db4fbc
JCL      - 775c5eb03a based on jdk-11.0.5+10)

Additional context
Add any other context about the problem here.

@fmhwong fmhwong added the Bug Something isn't working label Jun 4, 2020
@thisthat
Copy link
Member

thisthat commented Jun 4, 2020

io.opentelemetry.trace.DefaultTracerProvider is an API class, whereas OpenTelemetrySdk.getTracerProvider() tries to load an SDK class.
It looks like your application is not loading the SDK. Could you please attach your build script?

@fmhwong
Copy link
Author

fmhwong commented Jun 5, 2020

I ran ../gradlew fatJar from https://github.com/open-telemetry/opentelemetry-java/tree/master/examples/jaeger and used the jar file opentelemetry-examples-jaeger-all-0.1.0-SNAPSHOT.jar in the server.

@thisthat
Copy link
Member

thisthat commented Jun 5, 2020

Which application server are you using?

@fmhwong
Copy link
Author

fmhwong commented Jun 5, 2020

I was using https://github.com/OpenLiberty/open-liberty.

I added the code block at the top of this issue to a servlet filter. If I packaged the servlet filter in a WAR file and ran it on OpenLiberty, I didn't get the ClassCastException.

However, if I packaged the servlet filter inside a OSGi bundle, it always resulted in ClassCastException.

@jkwatson
Copy link
Contributor

Can you include more of the stack trace? I'd like to know where in the code this is actually being invoked.

@jkwatson
Copy link
Contributor

@fmhwong there hasn't been any activity on this in a while. Is this still an issue? Can we close it?

@jkwatson jkwatson added the release:required-for-ga Required for 1.0 GA release label Jul 21, 2020
@fmhwong
Copy link
Author

fmhwong commented Jul 21, 2020

Let me dig it up.

@fmhwong
Copy link
Author

fmhwong commented Jul 22, 2020

I investigated a bit more.

This line is trying to load the implementation of TracerProviderFactory but failed inside an OSGi bundle in OpenLiberty (probably due to missing configurations).

TracerProviderFactory tracerProviderFactory = loadSpi(TracerProviderFactory.class);

and therefore DefaultTracerProvider is used.

It failed at

return (TracerSdkProvider) ((Obfuscated<?>) OpenTelemetry.getTracerProvider()).unobfuscate();

with a ClassCastException as DefaultTracerProvider does not implement Obfuscated.

@jkwatson
Copy link
Contributor

I'm not very familiar with OSGI. Would this be resolved by #768?

@fmhwong
Copy link
Author

fmhwong commented Aug 4, 2020

Should the DefaultTracerProvider also implement Obfuscated?

@Oberon00
Copy link
Member

Oberon00 commented Aug 4, 2020

It would just throw at the cast to TracerSdkProvider then.

@jkwatson
Copy link
Contributor

I'm not very familiar with OSGI. Would this be resolved by #768?

@fmhwong any ideas on this question?

@jkwatson jkwatson added the priority:p2 Medium priority issues and bugs. label Aug 12, 2020
@fmhwong
Copy link
Author

fmhwong commented Aug 12, 2020

@jkwatson I am not sure #768 will help or not. I probably can work around this by changing some configuration in OpenLiberty bundles. I think DefaultTracerProvider should also implement Obfuscated so the ClassCastException can be avoided.

@jkwatson
Copy link
Contributor

I don't think that DefaultTracerProvider can itself implement Obfuscated. Are you suggesting that the OpenTelemetry instance should return an obfuscated wrapper for the DefaultTracerProvider like it does with one that is provided via SPI?

I'm not clear how this would solve your problem, since that would just make the OpenTelemetrySdk fail the cast, if it gets one from the OpenTelemetry global.

@jkwatson
Copy link
Contributor

From some cursory searching on the internet, it seems like OSGI and SPI don't work particularly well together. I would assume, therefore, that #768 would fix your issue.

@jkwatson
Copy link
Contributor

Given that this will require #768, I'm downgrading this to release:after-ga.

@jkwatson jkwatson added release:after-ga and removed release:required-for-ga Required for 1.0 GA release priority:p2 Medium priority issues and bugs. labels Sep 10, 2020
@jkwatson
Copy link
Contributor

I'm closing this as a duplicate of #768. Please re-open if that is not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants