WebSocket locally initiated spans ignore single-trace configuration
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- java
- Domain
- observability
Research direction
Start at WebsocketDecorator.onFrameStart and trace how the traceStarter and useDedicatedTraces branches select the span context for locally initiated operations. Reproduce the Jakarta WebSocket case with DD_TRACE_WEBSOCKET_MESSAGES_SEPARATE_TRACES=false, then verify that websocket.send and websocket.close share the handshake trace while the default true behavior remains unchanged.
Written by the indexing model from the issue text.
Description
Tracer Version(s)
1.65.1 and current master (a1b6599a5f9f8d803cfac89fa1c3befe41b8c33f)
Java Version(s)
Oracle JDK 21.0.3
JVM Vendor
Oracle JDK
Bug Report
When DD_TRACE_WEBSOCKET_MESSAGES_SEPARATE_TRACES=false, received messages and peer-initiated close spans use the handshake span context, but locally initiated websocket.send and websocket.close spans still use the currently active context.
If there is no active span when Session.close() or RemoteEndpoint.send*() is called, those spans become roots of new traces. If another business span is active, they join that trace instead. In both cases they have a different trace ID from the WebSocket handshake.
This behavior comes from WebsocketDecorator.onFrameStart: the useDedicatedTraces setting is only checked when traceStarter is true. The traceStarter == false branch always calls startSpan(..., operationName) without the handshake context.
This was reproduced with Jakarta WebSocket and Tyrus 2.2.0, but the behavior is in the shared WebSocket decorator and is not Tyrus-specific.
The current result for one short-lived connection is:
websocket.open trace=A
websocket.receive trace=A
websocket.send trace=B
websocket.close trace=C
Expected Behavior
The Java configuration documentation says that setting DD_TRACE_WEBSOCKET_MESSAGES_SEPARATE_TRACES=false causes all spans captured during the session to be in the same trace. Locally initiated send and close spans should therefore use the handshake trace as well:
websocket.open trace=A
websocket.receive trace=A
websocket.send trace=A
websocket.close trace=A
When the setting remains at its default value of true, the existing behavior of outgoing operations following the current trace and linking to the handshake should remain unchanged.
Documentation: https://docs.datadoghq.com/tracing/trace_collection/library_config/java/#websocket_messages
Reproduction Code
Session session = client.connectToServer(endpoint, config, uri);
session.getBasicRemote().sendText("hello");
session.close(new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "done"));
Run without an active application span around sendText and close, with:
DD_TRACE_WEBSOCKET_MESSAGES_SEPARATE_TRACES=false
DD_TRACE_WEBSOCKET_MESSAGES_ENABLED=true
Compare the trace IDs of the handshake, receive, send, and close spans.
- Dominant language
- Java
- Stars
- 737
- Forks
- 361
- Avg merge
- 3d 20h
- Merged PRs (30d)
- 173
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from DataDog/dd-trace-java
-
type: feature request
Difficulty 1/5 1-3 hours Newbie friendliness 70/100
DataDog/dd-trace-java#10245 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 62/100
DataDog/dd-trace-java#12608 ·
-
type: bug report
Difficulty 4/5 3-5 days Newbie friendliness 35/100
DataDog/dd-trace-java#12597 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
DataDog/dd-trace-java#12540 · 4 comments · 1 assignee ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
DataDog/dd-trace-java#12480 ·
All issues in DataDog/dd-trace-java
Similar issues
-
area-deployment area-integrations triage:bot-seen
Difficulty 2/5 Half a day Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
apache/flink-agents#1156 ·
-
[source-shopify] FAILED bulk operation without partialDataUrl is silently treated as successful Openarea/connectors autoteam community connectors/source/shopify needs-triage team/use type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100