diff --git a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/TracingHttpRequest.java b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/TracingHttpRequest.java index 9bdc687c250d..18846fc140a1 100644 --- a/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/TracingHttpRequest.java +++ b/instrumentation/jetty-httpclient/jetty-httpclient-12.0/library/src/main/java/io/opentelemetry/instrumentation/jetty/httpclient/v12_0/TracingHttpRequest.java @@ -14,8 +14,12 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; import org.eclipse.jetty.client.Response; +import org.eclipse.jetty.client.Result; import org.eclipse.jetty.client.transport.HttpConversation; import org.eclipse.jetty.client.transport.HttpRequest; +import org.eclipse.jetty.http.HttpField; +import org.eclipse.jetty.io.Content.Chunk; +import org.eclipse.jetty.io.Content.Source; class TracingHttpRequest extends HttpRequest { @@ -37,9 +41,84 @@ public void send(Response.CompleteListener listener) { // start span and attach listeners. JettyClientTracingListener.handleRequest(parentContext, this, instrumenter); super.send( - result -> { - try (Scope scope = openScope()) { - listener.onComplete(result); + new Response.Listener() { + @Override + public void onBegin(Response response) { + if (listener instanceof Response.BeginListener l) { + try (Scope scope = openScope()) { + l.onBegin(response); + } + } + } + + @Override + public void onComplete(Result result) { + try (Scope scope = openScope()) { + listener.onComplete(result); + } + } + + @Override + public void onContent(Response response, ByteBuffer content) { + if (listener instanceof Response.ContentListener l) { + try (Scope scope = openScope()) { + l.onContent(response, content); + } + } + } + + @Override + public void onContent(Response response, Chunk chunk, Runnable demander) { + if (listener instanceof Response.AsyncContentListener l) { + try (Scope scope = openScope()) { + l.onContent(response, chunk, demander); + } + } + } + + @Override + public void onContentSource(Response response, Source contentSource) { + if (listener instanceof Response.ContentSourceListener l) { + try (Scope scope = openScope()) { + l.onContentSource(response, contentSource); + } + } + } + + @Override + public void onFailure(Response response, Throwable failure) { + if (listener instanceof Response.FailureListener l) { + try (Scope scope = openScope()) { + l.onFailure(response, failure); + } + } + } + + @Override + public void onHeaders(Response response) { + if (listener instanceof Response.HeadersListener l) { + try (Scope scope = openScope()) { + l.onHeaders(response); + } + } + } + + @Override + public boolean onHeader(Response response, HttpField field) { + if (listener instanceof Response.HeaderListener l) { + try (Scope scope = openScope()) { + return l.onHeader(response, field); + } + } + } + + @Override + public void onSuccess(Response response) { + if (listener instanceof Response.SuccessListener l) { + try (Scope scope = openScope()) { + l.onSuccess(response); + } + } } }); }