Convert jaxrs-client-2.0 to instrumenter api
MODIFY
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ClientTracingFilter.java
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ClientTracingFilter.java
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.JaxRsClientSingletons.instrumenter;
import io.opentelemetry.context.Context;
import javax.annotation.Priority;
@@ -22,8 +22,8 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
@Override
public void filter(ClientRequestContext requestContext) {
Context parentContext = Context.current();
- if (tracer().shouldStartSpan(parentContext)) {
- Context context = tracer().startSpan(parentContext, requestContext, requestContext);
+ if (instrumenter().shouldStart(parentContext, requestContext)) {
+ Context context = instrumenter().start(parentContext, requestContext);
requestContext.setProperty(CONTEXT_PROPERTY_NAME, context);
}
}
@@ -33,7 +33,7 @@ public class ClientTracingFilter implements ClientRequestFilter, ClientResponseF
Object contextObj = requestContext.getProperty(CONTEXT_PROPERTY_NAME);
if (contextObj instanceof Context) {
Context context = (Context) contextObj;
- tracer().end(context, responseContext);
+ instrumenter().end(context, requestContext, responseContext, null);
}
}
}

ADD
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientHttpAttributesExtractor.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
+
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor;
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+final class JaxRsClientHttpAttributesExtractor
+ extends HttpAttributesExtractor<ClientRequestContext, ClientResponseContext> {
+
+ @Override
+ protected @Nullable String method(ClientRequestContext httpRequest) {
+ return httpRequest.getMethod();
+ }
+
+ @Override
+ protected String url(ClientRequestContext httpRequest) {
+ return httpRequest.getUri().toString();
+ }
+
+ @Override
+ protected @Nullable String target(ClientRequestContext httpRequest) {
+ StringBuilder result = new StringBuilder();
+ String path = httpRequest.getUri().getPath();
+ if (path != null) {
+ result.append(path);
+ }
+ String query = httpRequest.getUri().getQuery();
+ if (query != null) {
+ result.append('?');
+ result.append(query);
+ }
+ String fragment = httpRequest.getUri().getFragment();
+ if (fragment != null) {
+ result.append('#');
+ result.append(fragment);
+ }
+ return result.length() > 0 ? result.toString() : null;
+ }
+
+ @Override
+ protected @Nullable String host(ClientRequestContext httpRequest) {
+ return httpRequest.getUri().getHost();
+ }
+
+ @Override
+ protected @Nullable String scheme(ClientRequestContext httpRequest) {
+ return httpRequest.getUri().getScheme();
+ }
+
+ @Override
+ protected @Nullable String userAgent(ClientRequestContext httpRequest) {
+ return httpRequest.getHeaderString("User-Agent");
+ }
+
+ @Override
+ protected @Nullable Long requestContentLength(
+ ClientRequestContext httpRequest, @Nullable ClientResponseContext httpResponse) {
+ return null;
+ }
+
+ @Override
+ protected @Nullable Long requestContentLengthUncompressed(
+ ClientRequestContext httpRequest, @Nullable ClientResponseContext httpResponse) {
+ return null;
+ }
+
+ @Override
+ protected String flavor(
+ ClientRequestContext httpRequest, @Nullable ClientResponseContext httpResponse) {
+ return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
+ }
+
+ @Override
+ protected @Nullable Integer statusCode(
+ ClientRequestContext httpRequest, ClientResponseContext httpResponse) {
+ return httpResponse.getStatus();
+ }
+
+ @Override
+ protected @Nullable Long responseContentLength(
+ ClientRequestContext httpRequest, ClientResponseContext httpResponse) {
+ int length = httpResponse.getLength();
+ return length != -1 ? (long) length : null;
+ }
+
+ @Override
+ protected @Nullable Long responseContentLengthUncompressed(
+ ClientRequestContext httpRequest, ClientResponseContext httpResponse) {
+ return null;
+ }
+
+ @Override
+ protected @Nullable String route(ClientRequestContext httpRequest) {
+ return null;
+ }
+
+ @Override
+ protected @Nullable String serverName(
+ ClientRequestContext httpRequest, @Nullable ClientResponseContext httpResponse) {
+ return null;
+ }
+}

ADD
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientNetAttributesExtractor.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
+
+import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor;
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+final class JaxRsClientNetAttributesExtractor
+ extends NetAttributesExtractor<ClientRequestContext, ClientResponseContext> {
+
+ @Override
+ public String transport(ClientRequestContext request) {
+ return SemanticAttributes.NetTransportValues.IP_TCP;
+ }
+
+ @Override
+ public @Nullable String peerName(
+ ClientRequestContext request, @Nullable ClientResponseContext response) {
+ return request.getUri().getHost();
+ }
+
+ @Override
+ public Integer peerPort(ClientRequestContext request, @Nullable ClientResponseContext response) {
+ int port = request.getUri().getPort();
+ if (port != -1) {
+ return port;
+ }
+ return null;
+ }
+
+ @Override
+ public @Nullable String peerIp(
+ ClientRequestContext request, @Nullable ClientResponseContext response) {
+ return null;
+ }
+}

ADD
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientSingletons.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
+
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.instrumentation.api.instrumenter.ErrorCauseExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
+import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
+import io.opentelemetry.javaagent.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+
+public class JaxRsClientSingletons {
+ private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxrs-client-2.0";
+
+ private static final Instrumenter<ClientRequestContext, ClientResponseContext> INSTRUMENTER;
+
+ static {
+ HttpAttributesExtractor<ClientRequestContext, ClientResponseContext> httpAttributesExtractor =
+ new JaxRsClientHttpAttributesExtractor();
+ SpanNameExtractor<? super ClientRequestContext> spanNameExtractor =
+ HttpSpanNameExtractor.create(httpAttributesExtractor);
+ SpanStatusExtractor<? super ClientRequestContext, ? super ClientResponseContext>
+ spanStatusExtractor = HttpSpanStatusExtractor.create(httpAttributesExtractor);
+ JaxRsClientNetAttributesExtractor netAttributesExtractor =
+ new JaxRsClientNetAttributesExtractor();
+
+ INSTRUMENTER =
+ Instrumenter.<ClientRequestContext, ClientResponseContext>newBuilder(
+ GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
+ .setSpanStatusExtractor(spanStatusExtractor)
+ .setErrorCauseExtractor(
+ (throwable) -> {
+ if (throwable instanceof ProcessingException) {
+ throwable = throwable.getCause();
+ }
+ return ErrorCauseExtractor.jdk().extractCause(throwable);
+ })
+ .addAttributesExtractor(httpAttributesExtractor)
+ .addAttributesExtractor(netAttributesExtractor)
+ .addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor))
+ .addRequestMetrics(HttpClientMetrics.get())
+ .newClientInstrumenter(new InjectAdapter());
+ }
+
+ public static Instrumenter<ClientRequestContext, ClientResponseContext> instrumenter() {
+ return INSTRUMENTER;
+ }
+
+ private JaxRsClientSingletons() {}
+}

DELETE
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JaxRsClientTracer.java
-/*
- * 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.InjectAdapter.SETTER;
-
-import io.opentelemetry.context.propagation.TextMapSetter;
-import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
-import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes;
-import java.net.URI;
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.client.ClientRequestContext;
-import javax.ws.rs.client.ClientResponseContext;
-
-public class JaxRsClientTracer
- extends HttpClientTracer<ClientRequestContext, ClientRequestContext, ClientResponseContext> {
- private static final JaxRsClientTracer TRACER = new JaxRsClientTracer();
-
- private JaxRsClientTracer() {
- super(NetPeerAttributes.INSTANCE);
- }
-
- public static JaxRsClientTracer tracer() {
- return TRACER;
- }
-
- @Override
- protected String method(ClientRequestContext httpRequest) {
- return httpRequest.getMethod();
- }
-
- @Override
- protected URI url(ClientRequestContext httpRequest) {
- return httpRequest.getUri();
- }
-
- @Override
- protected Integer status(ClientResponseContext httpResponse) {
- return httpResponse.getStatus();
- }
-
- @Override
- protected String requestHeader(ClientRequestContext clientRequestContext, String name) {
- return clientRequestContext.getHeaderString(name);
- }
-
- @Override
- protected String responseHeader(ClientResponseContext clientResponseContext, String name) {
- return clientResponseContext.getHeaderString(name);
- }
-
- @Override
- protected TextMapSetter<ClientRequestContext> getSetter() {
- return SETTER;
- }
-
- @Override
- protected Throwable unwrapThrowable(Throwable throwable) {
- if (throwable instanceof ProcessingException) {
- throwable = throwable.getCause();
- }
- return super.unwrapThrowable(throwable);
- }
-
- @Override
- protected String getInstrumentationName() {
- return "io.opentelemetry.jaxrs-client-2.0";
- }
-}

MODIFY
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/test/groovy/JaxRsClientTest.groovy
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-common/javaagent/src/test/groovy/JaxRsClientTest.groovy
@@ -104,6 +104,10 @@ abstract class JaxRsClientTest extends HttpClientTest<Invocation.Builder> implem
"${SemanticAttributes.HTTP_METHOD.key}" method
"${SemanticAttributes.HTTP_STATUS_CODE.key}" statusCode
"${SemanticAttributes.HTTP_FLAVOR.key}" "1.1"
+ "${SemanticAttributes.HTTP_HOST.key}" "localhost"
+ "${SemanticAttributes.HTTP_SCHEME.key}" "http"
+ "${SemanticAttributes.HTTP_TARGET.key}" path
+ "${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH.key}" Long
}
}
serverSpan(it, 1, span(0))

MODIFY
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/CxfClientUtil.java
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-cxf-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/CxfClientUtil.java
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.JaxRsClientSingletons.instrumenter;
import io.opentelemetry.context.Context;
import javax.ws.rs.client.ClientRequestContext;
@@ -19,7 +19,7 @@ public final class CxfClientUtil {
new ClientRequestContextImpl(message, /* responseContext= */ false);
Object prop = context.getProperty(ClientTracingFilter.CONTEXT_PROPERTY_NAME);
if (prop instanceof Context) {
- tracer().endExceptionally((Context) prop, throwable);
+ instrumenter().end((Context) prop, context, null, throwable);
}
}

MODIFY
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-jersey-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JerseyClientUtil.java
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-jersey-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/JerseyClientUtil.java
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.JaxRsClientSingletons.instrumenter;
import io.opentelemetry.context.Context;
import org.glassfish.jersey.client.ClientRequest;
@@ -15,7 +15,7 @@ public final class JerseyClientUtil {
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);
+ instrumenter().end((Context) prop, context, null, exception);
}
}

ADD
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientHttpAttributesExtractor.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
+
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor;
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
+import javax.ws.rs.core.Response;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation;
+
+final class ResteasyClientHttpAttributesExtractor
+ extends HttpAttributesExtractor<ClientInvocation, Response> {
+
+ @Override
+ protected @Nullable String method(ClientInvocation httpRequest) {
+ return httpRequest.getMethod();
+ }
+
+ @Override
+ protected String url(ClientInvocation httpRequest) {
+ return httpRequest.getUri().toString();
+ }
+
+ @Override
+ protected @Nullable String target(ClientInvocation httpRequest) {
+ StringBuilder result = new StringBuilder();
+ String path = httpRequest.getUri().getPath();
+ if (path != null) {
+ result.append(path);
+ }
+ String query = httpRequest.getUri().getQuery();
+ if (query != null) {
+ result.append('?');
+ result.append(query);
+ }
+ String fragment = httpRequest.getUri().getFragment();
+ if (fragment != null) {
+ result.append('#');
+ result.append(fragment);
+ }
+ return result.length() > 0 ? result.toString() : null;
+ }
+
+ @Override
+ protected @Nullable String host(ClientInvocation httpRequest) {
+ return httpRequest.getUri().getHost();
+ }
+
+ @Override
+ protected @Nullable String scheme(ClientInvocation httpRequest) {
+ return httpRequest.getUri().getScheme();
+ }
+
+ @Override
+ protected @Nullable String userAgent(ClientInvocation httpRequest) {
+ return httpRequest.getHeaders().getHeader("User-Agent");
+ }
+
+ @Override
+ protected @Nullable Long requestContentLength(
+ ClientInvocation httpRequest, @Nullable Response httpResponse) {
+ return null;
+ }
+
+ @Override
+ protected @Nullable Long requestContentLengthUncompressed(
+ ClientInvocation httpRequest, @Nullable Response httpResponse) {
+ return null;
+ }
+
+ @Override
+ protected String flavor(ClientInvocation httpRequest, @Nullable Response httpResponse) {
+ return SemanticAttributes.HttpFlavorValues.HTTP_1_1;
+ }
+
+ @Override
+ protected @Nullable Integer statusCode(ClientInvocation httpRequest, Response httpResponse) {
+ return httpResponse.getStatus();
+ }
+
+ @Override
+ protected @Nullable Long responseContentLength(
+ ClientInvocation httpRequest, Response httpResponse) {
+ int length = httpResponse.getLength();
+ return length != -1 ? (long) length : null;
+ }
+
+ @Override
+ protected @Nullable Long responseContentLengthUncompressed(
+ ClientInvocation httpRequest, Response httpResponse) {
+ return null;
+ }
+
+ @Override
+ protected @Nullable String route(ClientInvocation httpRequest) {
+ return null;
+ }
+
+ @Override
+ protected @Nullable String serverName(
+ ClientInvocation httpRequest, @Nullable Response httpResponse) {
+ return null;
+ }
+}

MODIFY
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientInstrumentationModule.java
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientInstrumentationModule.java
package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
import static io.opentelemetry.javaagent.instrumentation.api.Java8BytecodeBridge.currentContext;
-import static io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.ResteasyClientTracer.tracer;
+import static io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0.ResteasyClientSingletons.instrumenter;
import static java.util.Collections.singletonList;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
@@ -32,7 +32,7 @@ import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation;
* proper scope handling.
*
* <p>This specific instrumentation will not conflict with {@link JaxRsClientInstrumentationModule},
- * because {@link JaxRsClientTracer} used by the latter checks against double client spans.
+ * because nested client spans are suppressed.
*/
@AutoService(InstrumentationModule.class)
public class ResteasyClientInstrumentationModule extends InstrumentationModule {
@@ -70,14 +70,15 @@ public class ResteasyClientInstrumentationModule extends InstrumentationModule {
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope) {
Context parentContext = currentContext();
- if (tracer().shouldStartSpan(parentContext)) {
- context = tracer().startSpan(parentContext, invocation, invocation);
+ if (instrumenter().shouldStart(parentContext, invocation)) {
+ context = instrumenter().start(parentContext, invocation);
scope = context.makeCurrent();
}
}
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(
+ @Advice.This ClientInvocation invocation,
@Advice.Return Response response,
@Advice.Thrown Throwable throwable,
@Advice.Local("otelContext") Context context,
@@ -87,11 +88,7 @@ public class ResteasyClientInstrumentationModule extends InstrumentationModule {
}
scope.close();
- if (throwable != null) {
- tracer().endExceptionally(context, throwable);
- } else {
- tracer().end(context, response);
- }
+ instrumenter().end(context, invocation, response, throwable);
}
}
}

ADD
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientNetAttributesExtractor.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
+
+import io.opentelemetry.instrumentation.api.instrumenter.net.NetAttributesExtractor;
+import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
+import javax.ws.rs.core.Response;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation;
+
+final class ResteasyClientNetAttributesExtractor
+ extends NetAttributesExtractor<ClientInvocation, Response> {
+
+ @Override
+ public String transport(ClientInvocation request) {
+ return SemanticAttributes.NetTransportValues.IP_TCP;
+ }
+
+ @Override
+ public @Nullable String peerName(ClientInvocation request, @Nullable Response response) {
+ return request.getUri().getHost();
+ }
+
+ @Override
+ public Integer peerPort(ClientInvocation request, @Nullable Response response) {
+ int port = request.getUri().getPort();
+ if (port != -1) {
+ return port;
+ }
+ return null;
+ }
+
+ @Override
+ public @Nullable String peerIp(ClientInvocation request, @Nullable Response response) {
+ return null;
+ }
+}

ADD
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientSingletons.java
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.jaxrsclient.v2_0;
+
+import io.opentelemetry.api.GlobalOpenTelemetry;
+import io.opentelemetry.instrumentation.api.instrumenter.ErrorCauseExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
+import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.SpanStatusExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpAttributesExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanNameExtractor;
+import io.opentelemetry.instrumentation.api.instrumenter.http.HttpSpanStatusExtractor;
+import io.opentelemetry.javaagent.instrumentation.api.instrumenter.PeerServiceAttributesExtractor;
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.core.Response;
+import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation;
+
+public class ResteasyClientSingletons {
+ private static final String INSTRUMENTATION_NAME =
+ "io.opentelemetry.jaxrs-client-2.0-resteasy-3.0";
+
+ private static final Instrumenter<ClientInvocation, Response> INSTRUMENTER;
+
+ static {
+ HttpAttributesExtractor<ClientInvocation, Response> httpAttributesExtractor =
+ new ResteasyClientHttpAttributesExtractor();
+ SpanNameExtractor<? super ClientInvocation> spanNameExtractor =
+ HttpSpanNameExtractor.create(httpAttributesExtractor);
+ SpanStatusExtractor<? super ClientInvocation, ? super Response> spanStatusExtractor =
+ HttpSpanStatusExtractor.create(httpAttributesExtractor);
+ ResteasyClientNetAttributesExtractor netAttributesExtractor =
+ new ResteasyClientNetAttributesExtractor();
+
+ INSTRUMENTER =
+ Instrumenter.<ClientInvocation, Response>newBuilder(
+ GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor)
+ .setSpanStatusExtractor(spanStatusExtractor)
+ .setErrorCauseExtractor(
+ (throwable) -> {
+ if (throwable instanceof ProcessingException) {
+ throwable = throwable.getCause();
+ }
+ return ErrorCauseExtractor.jdk().extractCause(throwable);
+ })
+ .addAttributesExtractor(httpAttributesExtractor)
+ .addAttributesExtractor(netAttributesExtractor)
+ .addAttributesExtractor(PeerServiceAttributesExtractor.create(netAttributesExtractor))
+ .addRequestMetrics(HttpClientMetrics.get())
+ .newClientInstrumenter(new ResteasyInjectAdapter());
+ }
+
+ public static Instrumenter<ClientInvocation, Response> instrumenter() {
+ return INSTRUMENTER;
+ }
+
+ private ResteasyClientSingletons() {}
+}

DELETE
instrumentation/jaxrs-client/jaxrs-client-2.0/jaxrs-client-2.0-resteasy-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/v2_0/ResteasyClientTracer.java
-/*
- * 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.ResteasyInjectAdapter.SETTER;
-
-import io.opentelemetry.context.propagation.TextMapSetter;
-import io.opentelemetry.instrumentation.api.tracer.HttpClientTracer;
-import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes;
-import java.net.URI;
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.core.Response;
-import org.jboss.resteasy.client.jaxrs.internal.ClientInvocation;
-
-public class ResteasyClientTracer
- extends HttpClientTracer<ClientInvocation, ClientInvocation, Response> {
- private static final ResteasyClientTracer TRACER = new ResteasyClientTracer();
-
- private ResteasyClientTracer() {
- super(NetPeerAttributes.INSTANCE);
- }
-
- public static ResteasyClientTracer tracer() {
- return TRACER;
- }
-
- @Override
- protected String method(ClientInvocation httpRequest) {
- return httpRequest.getMethod();
- }
-
- @Override
- protected URI url(ClientInvocation httpRequest) {
- return httpRequest.getUri();
- }
-
- @Override
- protected Integer status(Response httpResponse) {
- return httpResponse.getStatus();
- }
-
- @Override
- protected String requestHeader(ClientInvocation clientRequestContext, String name) {
- return clientRequestContext.getHeaders().getHeader(name);
- }
-
- @Override
- protected String responseHeader(Response httpResponse, String name) {
- return httpResponse.getHeaderString(name);
- }
-
- @Override
- protected TextMapSetter<ClientInvocation> getSetter() {
- return SETTER;
- }
-
- @Override
- protected Throwable unwrapThrowable(Throwable throwable) {
- if (throwable instanceof ProcessingException) {
- throwable = throwable.getCause();
- }
- return super.unwrapThrowable(throwable);
- }
-
- @Override
- protected String getInstrumentationName() {
- return "io.opentelemetry.jaxrs-client-2.0-resteasy-3.0";
- }
-}

Convert jaxrs-client-2.0 to instrumenter api (#3938)