quarkus: Restclient @WithSpan throws in java.lang.ClassCastException
Describe the bug
To be able to add a parameter to the trace, I added two annotations to rest client remote call @WithSpan and @SpanAttribute as described in the open telemetry documentation:
public interface RemoteRestClient {
@GET
@Path("/remote/{id}")
@WithSpan
Response getResponse(@SpanAttribute(value = "id") @PathParam("id") Long id) throws Exception;
}
This does not work however and the error is:
org.jboss.resteasy.spi.UnhandledException: java.lang.ClassCastException: class org.jboss.resteasy.microprofile.client.InvocationContextImpl cannot be cast to class io.quarkus.arc.ArcInvocationContext (org.jboss.resteasy.microprofile.client.InvocationContextImpl and io.quarkus.arc.ArcInvocationContext are in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @48524010)
The stacktrace below has been reversed to show the root cause first. [Click Here](http://localhost:8080/hello) to see the original stacktrace
java.lang.ClassCastException: class org.jboss.resteasy.microprofile.client.InvocationContextImpl cannot be cast to class io.quarkus.arc.ArcInvocationContext (org.jboss.resteasy.microprofile.client.InvocationContextImpl and io.quarkus.arc.ArcInvocationContext are in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @48524010)
at io.quarkus.opentelemetry.runtime.tracing.cdi.WithSpanInterceptor_Bean.intercept(Unknown Source)
at org.jboss.resteasy.microprofile.client.InvocationContextImpl$InterceptorInvocation.invoke(InvocationContextImpl.java:170)
at org.jboss.resteasy.microprofile.client.InvocationContextImpl.invokeNext(InvocationContextImpl.java:69)
at org.jboss.resteasy.microprofile.client.InvocationContextImpl.proceed(InvocationContextImpl.java:105)
at io.quarkus.restclient.runtime.QuarkusProxyInvocationHandler.invoke(QuarkusProxyInvocationHandler.java:158)
at jdk.proxy20/jdk.proxy20.$Proxy189.getResponse(Unknown Source)
at org.acme.RemoteRestClient_5d475da7d2c3784fa411823307f5b6e5171ceacd_Synthetic_ClientProxy.getResponse(Unknown Source)
Reproducer with test code-with-quarkus.tar.gz
or start with ./mvnw quarkus:dev and curl http://localhost:8080/hello
When I remove @WithSpan then it works but the parameter id is not propagated into the trace tags.
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Output of uname -a or ver
No response
Output of java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
No response
Build tool (ie. output of mvnw --version or gradlew --version)
No response
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 9 months ago
- Comments: 19 (16 by maintainers)
Thanks @manovotn for the code. I’ll debug what’s going on.
I was not saying that. It will work after the fix. What you mention is fair and I’ve now identified a gap in our implementation. We should have support for this annotation:
@AddingSpanAttributes. Created this: https://github.com/quarkusio/quarkus/issues/36138 In the future you will be able to use this new annotation.@manovotn PR is enough to fix the exception and later enable this new annotation to work.
I am not sure… To enable this particular case, the easiest place a workaround into
WithSpanInterceptor. But, like I said, this will break any other interceptor usingArcInvocationContext… The ultimate solution is not using two different interceptor chains but that would be a lot of work as you’d need to pre-generate code for rest client interfaces to register them as regular beans (similarly to what RR does).