Fix integration with jersey-client 2.30 (#2071)
* Fix integration with jetty-client 2.30 * make class final and add private constructor * Update instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/jaxrs-client-2.0-common-javaagent.gradle Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
This commit is contained in:
parent
97b8712e3b
commit
cdfe8e0afb
|
@ -35,8 +35,8 @@ dependencies {
|
|||
|
||||
testInstrumentation project(':instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent')
|
||||
|
||||
latestDepTestLibrary group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.27'
|
||||
latestDepTestLibrary group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.27'
|
||||
latestDepTestLibrary group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '2.+'
|
||||
latestDepTestLibrary group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.+'
|
||||
latestDepTestLibrary group: 'org.apache.cxf', name: 'cxf-rt-rs-client', version: '3.2.6'
|
||||
latestDepTestLibrary group: 'org.jboss.resteasy', name: 'resteasy-client', version: '3.0.26.Final'
|
||||
}
|
||||
|
|
|
@ -5,14 +5,12 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.JaxRsClientTracer.tracer;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.returns;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
import io.opentelemetry.context.Context;
|
||||
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
|
@ -71,10 +69,7 @@ public class JerseyClientInstrumentationModule extends InstrumentationModule {
|
|||
@Advice.FieldValue("requestContext") ClientRequest context,
|
||||
@Advice.Thrown Throwable throwable) {
|
||||
if (throwable != null) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.CONTEXT_PROPERTY_NAME);
|
||||
if (prop instanceof Context) {
|
||||
tracer().endExceptionally((Context) prop, throwable);
|
||||
}
|
||||
JerseyClientUtil.handleException(context, throwable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,9 +80,7 @@ public class JerseyClientInstrumentationModule extends InstrumentationModule {
|
|||
public static void handleError(
|
||||
@Advice.FieldValue("requestContext") ClientRequest context,
|
||||
@Advice.Return(readOnly = false) Future<?> future) {
|
||||
if (!(future instanceof WrappedFuture)) {
|
||||
future = new WrappedFuture<>(future, context);
|
||||
}
|
||||
future = JerseyClientUtil.addErrorReporting(context, future);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.JaxRsClientTracer.tracer;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import org.glassfish.jersey.client.ClientRequest;
|
||||
|
||||
public final class JerseyClientUtil {
|
||||
|
||||
public static Future<?> addErrorReporting(ClientRequest context, Future<?> future) {
|
||||
// since jersey 2.30 jersey internally uses CompletableFuture
|
||||
// we can't wrap it with WrappedFuture as it causes ClassCastException when casting
|
||||
// to CompletableFuture
|
||||
if (future instanceof CompletableFuture) {
|
||||
future =
|
||||
((CompletableFuture<?>) future)
|
||||
.whenComplete(
|
||||
(result, exception) -> {
|
||||
if (exception != null) {
|
||||
handleException(context, exception);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (!(future instanceof WrappedFuture)) {
|
||||
future = new WrappedFuture<>(future, context);
|
||||
}
|
||||
}
|
||||
|
||||
return future;
|
||||
}
|
||||
|
||||
public static void handleException(ClientRequest context, Throwable exception) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.CONTEXT_PROPERTY_NAME);
|
||||
if (prop instanceof Context) {
|
||||
tracer().endExceptionally((Context) prop, exception);
|
||||
}
|
||||
}
|
||||
|
||||
private JerseyClientUtil() {}
|
||||
}
|
|
@ -5,9 +5,8 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.JaxRsClientTracer.tracer;
|
||||
import static io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.JerseyClientUtil.handleException;
|
||||
|
||||
import io.opentelemetry.context.Context;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -44,10 +43,7 @@ public class WrappedFuture<T> implements Future<T> {
|
|||
try {
|
||||
return wrapped.get();
|
||||
} catch (ExecutionException e) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.CONTEXT_PROPERTY_NAME);
|
||||
if (prop instanceof Context) {
|
||||
tracer().endExceptionally((Context) prop, e.getCause());
|
||||
}
|
||||
handleException(context, e.getCause());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
@ -58,10 +54,7 @@ public class WrappedFuture<T> implements Future<T> {
|
|||
try {
|
||||
return wrapped.get(timeout, unit);
|
||||
} catch (ExecutionException e) {
|
||||
Object prop = context.getProperty(ClientTracingFilter.CONTEXT_PROPERTY_NAME);
|
||||
if (prop instanceof Context) {
|
||||
tracer().endExceptionally((Context) prop, e.getCause());
|
||||
}
|
||||
handleException(context, e.getCause());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue