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

Can't use @SpanAttribute annotation with Websockets.NEXT @OnTextMessage #43412

Open
edeandrea opened this issue Sep 20, 2024 · 9 comments
Open

Comments

@edeandrea
Copy link
Contributor

edeandrea commented Sep 20, 2024

Describe the bug

When combining WebSockets.NEXT & OpenTelemetry, I can't seem to be able to add an @SpanAttribute annotation to a method parameter of an @OnTextMessage, like this:

@OnTextMessage
@WithSpan("ChatMessage")
public ClaimBotQueryResponse onMessage(@SpanAttribute("arg.chatQuery") ClaimBotQuery query) {
    Log.infof("Got chat query: %s", query);
    var response = new ClaimBotQueryResponse("token", this.bot.chat(query), "");
    Log.debugf("Got chat response: %s", response);

    return response;
}

Expected behavior

No response

Actual behavior

I get this error when trying to run dev mode:

2024-09-20 11:21:44,087 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.websockets.next.deployment.WebSocketProcessor#collectEndpoints threw an exception: io.quarkus.websockets.next.WebSocketException: Unable to inject @OnTextMessage callback parameter 'query' declared on org.parasol.resources.ClaimWebsocketChatBot#onMessage(): no injector found
        at io.quarkus.websockets.next.deployment.Callback.collectArguments(Callback.java:208)
        at io.quarkus.websockets.next.deployment.Callback.<init>(Callback.java:65)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.findCallback(WebSocketProcessor.java:1425)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.findCallback(WebSocketProcessor.java:1410)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.collectEndpoints(WebSocketProcessor.java:355)
        at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
        at java.base/java.lang.Thread.run(Thread.java:1583)
        at org.jboss.threads.JBossThread.run(JBossThread.java:483)

        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:354)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:272)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:62)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:91)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:430)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:57)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:138)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:93)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:131)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.websockets.next.deployment.WebSocketProcessor#collectEndpoints threw an exception: io.quarkus.websockets.next.WebSocketException: Unable to inject @OnTextMessage callback parameter 'query' declared on org.parasol.resources.ClaimWebsocketChatBot#onMessage(): no injector found
        at io.quarkus.websockets.next.deployment.Callback.collectArguments(Callback.java:208)
        at io.quarkus.websockets.next.deployment.Callback.<init>(Callback.java:65)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.findCallback(WebSocketProcessor.java:1425)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.findCallback(WebSocketProcessor.java:1410)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.collectEndpoints(WebSocketProcessor.java:355)
        at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
        at java.base/java.lang.Thread.run(Thread.java:1583)
        at org.jboss.threads.JBossThread.run(JBossThread.java:483)

        at io.quarkus.builder.Execution.run(Execution.java:123)
        at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:79)
        at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:161)
        at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:350)
        ... 9 more
Caused by: io.quarkus.websockets.next.WebSocketException: Unable to inject @OnTextMessage callback parameter 'query' declared on org.parasol.resources.ClaimWebsocketChatBot#onMessage(): no injector found
        at io.quarkus.websockets.next.deployment.Callback.collectArguments(Callback.java:208)
        at io.quarkus.websockets.next.deployment.Callback.<init>(Callback.java:65)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.findCallback(WebSocketProcessor.java:1425)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.findCallback(WebSocketProcessor.java:1410)
        at io.quarkus.websockets.next.deployment.WebSocketProcessor.collectEndpoints(WebSocketProcessor.java:355)
        at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2516)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2495)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1521)
        at java.base/java.lang.Thread.run(Thread.java:1583)
        at org.jboss.threads.JBossThread.run(JBossThread.java:483)

How to Reproduce?

Reproducer: parasol-insurance.zip

  1. Download & unzip reproducer
  2. cd parasol-insurance
  3. ./mvnw clean quarkus:dev
  4. Observe above stack trace

Output of uname -a or ver

Darwin edeandrea-m1pro 24.0.0 Darwin Kernel Version 24.0.0: Mon Aug 12 20:51:54 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode)

Quarkus version or git rev

3.14.4

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae)
Maven home: /Users/edeandre/.m2/wrapper/dists/apache-maven-3.9.6/a53741d1
Java version: 21.0.4, vendor: Eclipse Adoptium, runtime: /Users/edeandre/.sdkman/candidates/java/21.0.4-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "15.0", arch: "aarch64", family: "mac"

Additional information

No response

@geoand
Copy link
Contributor

geoand commented Sep 21, 2024

cc @brunobat @mkouba @michalvavrik

@mkouba
Copy link
Contributor

mkouba commented Sep 23, 2024

When combining WebSockets.NEXT & OpenTelemetry, I can't seem to be able to add an @SpanAttribute annotation to a method parameter of an @OnTextMessage, like this:

@edeandrea OpenTelemetry is not fully supported yet. There's an open enhancement issue: #39143

@geoand
Copy link
Contributor

geoand commented Sep 23, 2024

@mkouba should we close this as a duplicate of #39143?

@mkouba
Copy link
Contributor

mkouba commented Sep 23, 2024

@mkouba should we close this as a duplicate of #39143?

I'd keep this issue open for now (unless Bruno and Michal object). I don't know how the @WithSpan + @SpanAttribute("arg.chatQuery") combo works and it could be also out of scope of #39143 🤷.

@geoand geoand added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Sep 24, 2024
@brunobat
Copy link
Contributor

@SpanAttribute() just adds the value of a particular method parameter to the span, as an attribute.
It's syntactic sugar.

@mkouba
Copy link
Contributor

mkouba commented Sep 24, 2024

@SpanAttribute() just adds the value of a particular method parameter to the span, as an attribute. It's syntactic sugar.

Well, but it depens on how it's implemented. In WS Next the validation would most likely fail because it's an unsupported method parameter. I guess that normally it's "injected" by the interceptor, right?

@brunobat
Copy link
Contributor

brunobat commented Sep 24, 2024

@SpanAttribute() just adds the value of a particular method parameter to the span, as an attribute. It's syntactic sugar.

Well, but it depens on how it's implemented. In WS Next the validation would most likely fail because it's an unsupported method parameter. I guess that normally it's "injected" by the interceptor, right?

This comes from the OTel spec. The annotation is just used to extract, in the example above, the following key pair and place it in the attributes of the span: arg.chatQuery=${query}, however, the query value must be a string... Not sure what will happen when used with ClaimBotQuery, @edeandrea.

@edeandrea
Copy link
Contributor Author

Not sure what will happen when used with ClaimBotQuery, @edeandrea.

Wouldn't/shouldn't it just call .toString()? Thats what I see when I do similar things in other places.

@mkouba
Copy link
Contributor

mkouba commented Sep 24, 2024

@SpanAttribute() just adds the value of a particular method parameter to the span, as an attribute. It's syntactic sugar.

Well, but it depens on how it's implemented. In WS Next the validation would most likely fail because it's an unsupported method parameter. I guess that normally it's "injected" by the interceptor, right?

This comes from the OTel spec. The annotation is just used to extract, in the example above, the following key pair and place it in the attributes of the span: arg.chatQuery=${query}, however, the query value must be a string... Not sure what will happen when used with ClaimBotQuery, @edeandrea.

I do understand that it's mandated by the spec. What I'm saying is that the validation of the WS next callback method will fail because it has some special requirements. I was asking about the implementation because a regular CDI interceptor would not work.

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

No branches or pull requests

4 participants