Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2635b84
Add Jetty 12 native WebSocket tracing and fix upgrade span completion
ygree Sep 28, 2026
f8975b9
Convert Jetty 12 WebSocket tests to Java and JUnit 5
ygree Sep 29, 2026
c78ea6e
Refactor Jetty 12 WebSocket advice into instrumentation classes and s…
ygree Sep 29, 2026
e5375ba
Fix Jetty 12 WebSocket tracing for boxed-Void handlers
ygree Sep 29, 2026
7c4584c
Move Jetty WebSocket upgrade test into client instrumentation module
ygree Sep 29, 2026
6dacd01
Extract shared Jetty WebSocket endpoint factory and clarify test names
ygree Sep 29, 2026
af473db
Fix Jetty 12 WebSocket Java tests to target Java 17
ygree Sep 29, 2026
63206fd
Validate Jetty WebSocket upgrade method compatibility with muzzle
ygree Oct 2, 2026
46d005b
Trace messages sent through Jetty 12’s native WebSocket API
ygree Oct 2, 2026
de874e5
Fix lost WebSocket send errors after Jetty connection closure
ygree Oct 2, 2026
333e301
Track Jetty 12.0 patch releases in latest-dependency tests and Muzzle.
ygree Oct 6, 2026
f8e0fdd
Trace Jetty 12 native streaming WebSocket handlers
ygree Oct 6, 2026
3c32223
Fix Jetty 12 WebSocket handshake spans for swallowed upgrade failures
ygree Oct 6, 2026
32b7140
Fix lost receive errors after Jetty WebSocket peer close
ygree Oct 7, 2026
572a50e
Add Muzzle guard and tests to prevent partial instrumentation on Jett…
ygree Oct 7, 2026
449cb65
Fix Jetty EE9 Muzzle selection and verify EE modules reject Jetty 12.1+
ygree Oct 7, 2026
0e4b096
Add tests for native Jetty WebSocket client tracing
ygree Oct 8, 2026
5e43379
Trace native Jetty WebSocket client receives
ygree Oct 8, 2026
24c6afe
Reduce native Jetty WebSocket tracing overhead
ygree Oct 8, 2026
a66ef77
Simplify native Jetty WebSocket tracing tests
ygree Oct 8, 2026
a39a803
Fix Jetty 12 WebSocket text receive spans finishing before handler exit
ygree Oct 13, 2026
66e7429
Align Jetty 12 WebSocket client send tracing
ygree Oct 13, 2026
1e670c3
Fix SpotBugs warnings in Jetty 12 WebSocket receive tracing
ygree Oct 13, 2026
ea2e598
Merge master into
ygree Oct 20, 2026
0b6a583
Merge master into
ygree Oct 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ muzzle {
javaVersion = "17"
assertInverse = true
}
pass {
group = "org.eclipse.jetty.websocket"
module = "jetty-websocket-core-client"
versions = "[12,)"
javaVersion = "17"
}
}

tracerJava {
Expand All @@ -18,10 +24,6 @@ tracerJava {

addTestSuiteForDir('latestDepTest', 'test')

tasks.named("compileMain_java17Java", JavaCompile) {
Comment thread
ygree marked this conversation as resolved.
configureCompiler(it, JavaVersion.VERSION_17)
}

configurations.matching { it.name.startsWith('test') || it.name.startsWith('latestDepTest') }.configureEach {
it.resolutionStrategy {
force group: 'org.slf4j', name: 'slf4j-api', version: libs.versions.slf4j.get()
Expand All @@ -30,6 +32,7 @@ configurations.matching { it.name.startsWith('test') || it.name.startsWith('late

dependencies {
main_java17CompileOnly group: 'org.eclipse.jetty', name: 'jetty-client', version: '12.0.0'
main_java17CompileOnly group: 'org.eclipse.jetty.websocket', name: 'jetty-websocket-core-client', version: '12.0.0'
// to test conflicts
testImplementation(project(':dd-java-agent:instrumentation:jetty:jetty-client:jetty-client-9.1'))
testImplementation(project(':dd-java-agent:instrumentation:jetty:jetty-client:jetty-client-10.0'))
Expand All @@ -40,5 +43,11 @@ dependencies {
}
testImplementation project(':dd-java-agent:instrumentation:jetty:jetty-util-9.4.31')
testImplementation group: 'org.eclipse.jetty', name: 'jetty-client', version: '12.0.0'
testImplementation 'org.eclipse.jetty.websocket:jetty-websocket-jetty-client:12.0.0'
testImplementation 'org.eclipse.jetty.websocket:jetty-websocket-jetty-server:12.0.0'
testImplementation libs.bundles.mockito
testRuntimeOnly project(':dd-java-agent:instrumentation:jetty:jetty-server:jetty-server-12.0')
latestDepTestImplementation group: 'org.eclipse.jetty', name: 'jetty-client', version: '12.+'
latestDepTestImplementation 'org.eclipse.jetty.websocket:jetty-websocket-jetty-client:12.+'
latestDepTestImplementation 'org.eclipse.jetty.websocket:jetty-websocket-jetty-server:12.+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ org.codenarc:CodeNarc:3.7.0=codenarc
org.dom4j:dom4j:2.2.0=spotbugs
org.eclipse.jetty.compression:jetty-compression-common:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.compression:jetty-compression-gzip:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-core-client:12.0.0=main_java17CompileClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-core-client:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-core-common:12.0.0=main_java17CompileClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-core-common:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-core-server:12.0.0=testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-core-server:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-api:12.0.0=testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-api:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-client:12.0.0=testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-client:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-common:12.0.0=testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-common:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-server:12.0.0=testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty.websocket:jetty-websocket-jetty-server:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty:jetty-alpn-client:12.0.0=main_java17CompileClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty:jetty-alpn-client:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty:jetty-client:12.0.0=main_java17CompileClasspath,testCompileClasspath,testRuntimeClasspath
Expand All @@ -90,6 +104,8 @@ org.eclipse.jetty:jetty-http:12.0.0=main_java17CompileClasspath,testCompileClass
org.eclipse.jetty:jetty-http:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty:jetty-io:12.0.0=main_java17CompileClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty:jetty-io:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty:jetty-server:12.0.0=testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty:jetty-server:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.eclipse.jetty:jetty-util:12.0.0=main_java17CompileClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jetty:jetty-util:12.1.14=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath
org.gmetrics:GMetrics:2.1.0=codenarc
Expand All @@ -109,7 +125,8 @@ org.junit.platform:junit-platform-runner:1.14.1=latestDepTestRuntimeClasspath,te
org.junit.platform:junit-platform-suite-api:1.14.1=latestDepTestRuntimeClasspath,testRuntimeClasspath
org.junit.platform:junit-platform-suite-commons:1.14.1=latestDepTestRuntimeClasspath,testRuntimeClasspath
org.junit:junit-bom:5.14.1=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.mockito:mockito-core:4.4.0=latestDepTestRuntimeClasspath,testRuntimeClasspath
org.mockito:mockito-core:4.4.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.mockito:mockito-junit-jupiter:4.4.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.objenesis:objenesis:3.3=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=latestDepTestCompileClasspath,latestDepTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ow2.asm:asm-analysis:9.10.1=spotbugs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public JettyHttpClientInstrumentation() {
super("jetty-client");
}

@Override
public String muzzleDirective() {
return "jetty-client";
}

@Override
public String instrumentedType() {
return "org.eclipse.jetty.client.transport.HttpRequest";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package datadog.trace.instrumentation.jetty_client12;

import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activateSpan;
import static datadog.trace.instrumentation.jetty_client12.JettyClientDecorator.DECORATE;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;

import com.google.auto.service.AutoService;
import datadog.context.ContextScope;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.agent.tooling.InstrumenterModule;
import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import java.util.Map;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import net.bytebuddy.asm.Advice;
import org.eclipse.jetty.client.Request;
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;

@AutoService(InstrumenterModule.class)
public class JettyWebSocketUpgradeInstrumentation extends InstrumenterModule.Tracing
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice {
public JettyWebSocketUpgradeInstrumentation() {
super("jetty-client");
}

@Override
public String muzzleDirective() {
return "jetty-websocket-core-client";
}

@Override
public String instrumentedType() {
return "org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest";
}

@Override
public String[] helperClassNames() {
return new String[] {packageName + ".JettyClientDecorator"};
}

@Override
public Map<String, String> contextStore() {
return singletonMap("org.eclipse.jetty.client.Request", AgentSpan.class.getName());
}

@Override
public void methodAdvice(MethodTransformer transformer) {
transformer.applyAdvice(
named("upgrade")
.and(takesArguments(2))
.and(takesArgument(0, named("org.eclipse.jetty.client.Response")))
.and(takesArgument(1, named("org.eclipse.jetty.io.EndPoint"))),
getClass().getName() + "$WebSocketUpgradeAdvice");
}

public static class WebSocketUpgradeAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static ContextScope beforeUpgrade(@Advice.Argument(0) Response response) {
AgentSpan span =
InstrumentationContext.get(Request.class, AgentSpan.class).get(response.getRequest());
return span == null ? null : activateSpan(span);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void afterUpgrade(
@Advice.Argument(0) Response response,
@Advice.FieldValue("futureCoreSession") CompletableFuture<?> futureCoreSession,
@Advice.Enter ContextScope scope,
@Advice.Thrown Throwable failure) {
AgentSpan span =
InstrumentationContext.get(Request.class, AgentSpan.class).get(response.getRequest());
try {
if (span != null && failure == null) {
Comment thread
ygree marked this conversation as resolved.
// Upgrades bypass response completion listeners even when endpoint failures are
// swallowed.
DECORATE.onResponse(span, response);
try {
futureCoreSession.getNow(null);
} catch (CompletionException e) {
DECORATE.onError(span, e.getCause());
} catch (CancellationException e) {
DECORATE.onError(span, e);
}
DECORATE.beforeFinish(span);
}
} finally {
if (scope != null) {
scope.close();
}
if (span != null && failure == null) {
span.finish();
}
}
}

/**
* Lets Muzzle fail CI if the upgrade method is removed or its signature changes, instead of
* silently skipping instrumentation.
*/
private void muzzleCheck(
CoreClientUpgradeRequest request, Response response, EndPoint endPoint) {
request.upgrade(response, endPoint);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import static datadog.trace.agent.test.assertions.SpanMatcher.span;
import static datadog.trace.agent.test.assertions.TraceMatcher.trace;
import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.regex.Pattern.compile;
import static java.util.regex.Pattern.quote;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.AdditionalAnswers.delegatesTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;

import datadog.trace.agent.test.AbstractInstrumentationTest;
import datadog.trace.api.DDSpanTypes;
import datadog.trace.core.DDSpan;
import java.net.URI;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.eclipse.jetty.client.Response;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.client.CoreClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
import org.eclipse.jetty.websocket.server.WebSocketUpgradeHandler;
import org.junit.jupiter.api.Test;

class JettyWebSocketUpgradeTest extends AbstractInstrumentationTest {
@Test
void httpClientSpanFinishesWhenWebSocketUpgradeSucceeds() throws Exception {
Server server = new Server(0);
WebSocketClient client = new WebSocketClient();
try {
URI uri = startServer(server);
client.start();

Session session = client.connect(new Endpoint(), uri).get(5, SECONDS);

assertTrue(session.isOpen());
// The HTTP handshake must be reported before the WebSocket connection closes.
assertTraces(
trace(
span()
.operationName(compile(quote("http.request")))
.resourceName(compile(quote("GET /upgrade")))
.type(DDSpanTypes.HTTP_CLIENT)
.root()
.error(false)),
trace(span().type(DDSpanTypes.HTTP_SERVER).error(false)));
DDSpan handshake =
writer.stream()
.flatMap(List::stream)
.filter(s -> "client".equals(s.getTag("span.kind")))
.findFirst()
.orElseThrow(() -> new AssertionError("Missing client handshake span"));
assertEquals("jetty-client", handshake.getTag("component").toString());
assertEquals("client", handshake.getTag("span.kind"));
assertEquals(101, handshake.getTag("http.status_code"));
} finally {
try {
client.stop();
} finally {
server.stop();
}
}
}

@Test
void httpClientSpanRecordsFailureSwallowedByWebSocketUpgrade() throws Exception {
Server server = new Server(0);
WebSocketCoreClient client = new WebSocketCoreClient();
try {
URI uri = startServer(server);
client.start();
IllegalStateException upgradeFailure = new IllegalStateException("Endpoint upgrade failed");
FrameHandler frameHandler = mock(FrameHandler.class);
CoreClientUpgradeRequest request =
new CoreClientUpgradeRequest(client, uri) {
@Override
public FrameHandler getFrameHandler() {
return frameHandler;
}

@Override
public void upgrade(Response response, EndPoint endPoint) {
EndPoint failingEndPoint = mock(EndPoint.class, delegatesTo(endPoint));
doThrow(upgradeFailure).when(failingEndPoint).upgrade(any(Connection.class));
super.upgrade(response, failingEndPoint);
}
};

ExecutionException failure =
assertThrows(ExecutionException.class, () -> client.connect(request).get(5, SECONDS));
assertSame(upgradeFailure, failure.getCause());

assertTraces(
trace(
span()
.operationName(compile(quote("http.request")))
.resourceName(compile(quote("GET /upgrade")))
.type(DDSpanTypes.HTTP_CLIENT)
.root()
.error(true)),
trace(span().type(DDSpanTypes.HTTP_SERVER).error(false)));
DDSpan handshake =
writer.stream()
.flatMap(List::stream)
.filter(s -> "client".equals(s.getTag("span.kind")))
.findFirst()
.orElseThrow(() -> new AssertionError("Missing client handshake span"));
assertEquals(101, handshake.getTag("http.status_code"));
assertEquals(IllegalStateException.class.getName(), handshake.getTag("error.type"));
assertEquals(upgradeFailure.getMessage(), handshake.getTag("error.message"));
} finally {
try {
client.stop();
} finally {
server.stop();
}
}
}

private static URI startServer(Server server) throws Exception {
ContextHandler context = new ContextHandler("/");
server.setHandler(context);
context.setHandler(
WebSocketUpgradeHandler.from(server, context)
.configure(
container ->
container.addMapping(
"/upgrade", (request, response, callback) -> new Endpoint())));
server.start();
return URI.create(
"ws://localhost:"
+ ((ServerConnector) server.getConnectors()[0]).getLocalPort()
+ "/upgrade");
}

public static class Endpoint implements Session.Listener.AutoDemanding {}
}
Loading
Loading