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

jetty9 http client: don't implement Response.CompleteListener #11579

Merged
Merged
Changes from all commits
Commits
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
jetty9 http client: don't implement Response.CompleteListener
  • Loading branch information
laurit committed Jun 13, 2024
commit 9681724e934b3fd45f5bd863c0566229c67dfe35
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javax.annotation.Nullable;
import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;

/**
* JettyHttpClient9TracingInterceptor does three jobs stimulated from the Jetty Request object from
Expand All @@ -32,8 +31,7 @@ public final class JettyHttpClient9TracingInterceptor
implements Request.BeginListener,
Request.FailureListener,
Response.SuccessListener,
Response.FailureListener,
Response.CompleteListener {
Response.FailureListener {

private static final Logger logger =
Logger.getLogger(JettyHttpClient9TracingInterceptor.class.getName());
Expand Down Expand Up @@ -88,7 +86,6 @@ public void attachToRequest(Request jettyRequest) {
}

private void wrapRequestListeners(List<Request.RequestListener> requestListeners) {

ListIterator<Request.RequestListener> iterator = requestListeners.listIterator();

while (iterator.hasNext()) {
Expand Down Expand Up @@ -125,7 +122,6 @@ private void wrapRequestListeners(List<Request.RequestListener> requestListeners
}

private void startSpan(Request request) {

if (!instrumenter.shouldStart(this.parentContext, request)) {
return;
}
Expand All @@ -135,14 +131,11 @@ private void startSpan(Request request) {
@Override
public void onBegin(Request request) {}

@Override
public void onComplete(Result result) {
closeIfPossible(result.getResponse());
}

@Override
public void onSuccess(Response response) {
closeIfPossible(response);
if (this.context != null) {
instrumenter.end(this.context, response.getRequest(), response, null);
}
Comment on lines +136 to +138
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this.context != null) {
instrumenter.end(this.context, response.getRequest(), response, null);
}
if (this.context != null) {
instrumenter.end(this.context, response.getRequest(), response, null);
} else {
logger.fine("onSuccess - could not find an otel context");
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this log line really useful? Looking at the code currently context being null doesn't really indicate that anything is wrong. Imo it would be better to refactor this so that the listener isn't added at all when span isn't started.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo it would be better to refactor this so that the listener isn't added at all when span isn't started.
👍

}

@Override
Expand All @@ -158,13 +151,4 @@ public void onFailure(Response response, Throwable t) {
instrumenter.end(this.context, response.getRequest(), response, t);
}
}

private void closeIfPossible(Response response) {

if (this.context != null) {
instrumenter.end(this.context, response.getRequest(), response, null);
} else {
logger.fine("onComplete - could not find an otel context");
}
}
}
Loading