diff --git a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Singletons.java b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Singletons.java index 2c86c8829f7e..d5012c5426ba 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Singletons.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/ElasticsearchRest5Singletons.java @@ -7,14 +7,15 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestInstrumenterFactory; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestRequest; import org.elasticsearch.client.Response; public final class ElasticsearchRest5Singletons { - private static final Instrumenter INSTRUMENTER = + private static final Instrumenter INSTRUMENTER = ElasticsearchRestInstrumenterFactory.create("io.opentelemetry.elasticsearch-rest-5.0"); - public static Instrumenter instrumenter() { + public static Instrumenter instrumenter() { return INSTRUMENTER; } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/RestClientInstrumentation.java b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/RestClientInstrumentation.java index f616c7d7f56d..85dd0ffc2491 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/RestClientInstrumentation.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v5_0/RestClientInstrumentation.java @@ -17,6 +17,7 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.RestResponseListener; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; @@ -48,13 +49,13 @@ public static class PerformRequestAsyncAdvice { public static void onEnter( @Advice.Argument(0) String method, @Advice.Argument(1) String endpoint, - @Advice.Local("otelRequest") String request, + @Advice.Local("otelRequest") ElasticsearchRestRequest request, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope, @Advice.Argument(value = 5, readOnly = false) ResponseListener responseListener) { Context parentContext = currentContext(); - request = method + " " + endpoint; + request = ElasticsearchRestRequest.create(method, endpoint); if (!instrumenter().shouldStart(parentContext, request)) { return; } @@ -70,7 +71,7 @@ public static void onEnter( @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( @Advice.Thrown Throwable throwable, - @Advice.Local("otelRequest") String request, + @Advice.Local("otelRequest") ElasticsearchRestRequest request, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { diff --git a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy index c73f8c9e4716..a53d738db5d5 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy +++ b/instrumentation/elasticsearch/elasticsearch-rest-5.0/javaagent/src/test/groovy/ElasticsearchRest5Test.groovy @@ -71,12 +71,13 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 1) { span(0) { - name "GET _cluster/health" + name "GET" kind CLIENT hasNoParent() attributes { "$SemanticAttributes.DB_SYSTEM" "elasticsearch" - "$SemanticAttributes.DB_OPERATION" "GET _cluster/health" + "$SemanticAttributes.DB_OPERATION" "GET" + "$SemanticAttributes.DB_STATEMENT" "GET _cluster/health" "$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME" httpHost.hostName "$SemanticAttributes.NET_PEER_PORT" httpHost.port @@ -130,12 +131,13 @@ class ElasticsearchRest5Test extends AgentInstrumentationSpecification { hasNoParent() } span(1) { - name "GET _cluster/health" + name "GET" kind CLIENT childOf(span(0)) attributes { "$SemanticAttributes.DB_SYSTEM" "elasticsearch" - "$SemanticAttributes.DB_OPERATION" "GET _cluster/health" + "$SemanticAttributes.DB_OPERATION" "GET" + "$SemanticAttributes.DB_STATEMENT" "GET _cluster/health" "$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME" httpHost.hostName "$SemanticAttributes.NET_PEER_PORT" httpHost.port diff --git a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Singletons.java b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Singletons.java index 82270208b381..2b82e991f941 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Singletons.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/ElasticsearchRest6Singletons.java @@ -7,14 +7,15 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestInstrumenterFactory; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestRequest; import org.elasticsearch.client.Response; public final class ElasticsearchRest6Singletons { - private static final Instrumenter INSTRUMENTER = + private static final Instrumenter INSTRUMENTER = ElasticsearchRestInstrumenterFactory.create("io.opentelemetry.elasticsearch-rest-6.4"); - public static Instrumenter instrumenter() { + public static Instrumenter instrumenter() { return INSTRUMENTER; } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/RestClientInstrumentation.java b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/RestClientInstrumentation.java index 5582fd11e55e..a150e146c14f 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/RestClientInstrumentation.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v6_4/RestClientInstrumentation.java @@ -16,6 +16,7 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.RestResponseListener; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; @@ -47,12 +48,12 @@ public static class PerformRequestAsyncAdvice { public static void onEnter( @Advice.Argument(0) Request request, @Advice.Argument(value = 1, readOnly = false) ResponseListener responseListener, - @Advice.Local("otelRequest") String otelRequest, + @Advice.Local("otelRequest") ElasticsearchRestRequest otelRequest, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { Context parentContext = currentContext(); - otelRequest = request.getMethod() + " " + request.getEndpoint(); + otelRequest = ElasticsearchRestRequest.create(request.getMethod(), request.getEndpoint()); if (!instrumenter().shouldStart(parentContext, otelRequest)) { return; } @@ -68,7 +69,7 @@ public static void onEnter( @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( @Advice.Thrown Throwable throwable, - @Advice.Local("otelRequest") String otelRequest, + @Advice.Local("otelRequest") ElasticsearchRestRequest otelRequest, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { diff --git a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy index 94c6ebbb1b5c..885f4f50ddf2 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy +++ b/instrumentation/elasticsearch/elasticsearch-rest-6.4/javaagent/src/test/groovy/ElasticsearchRest6Test.groovy @@ -66,12 +66,13 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 1) { span(0) { - name "GET _cluster/health" + name "GET" kind CLIENT hasNoParent() attributes { "$SemanticAttributes.DB_SYSTEM" "elasticsearch" - "$SemanticAttributes.DB_OPERATION" "GET _cluster/health" + "$SemanticAttributes.DB_OPERATION" "GET" + "$SemanticAttributes.DB_STATEMENT" "GET _cluster/health" "$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME" httpHost.hostName "$SemanticAttributes.NET_PEER_PORT" httpHost.port @@ -124,12 +125,13 @@ class ElasticsearchRest6Test extends AgentInstrumentationSpecification { hasNoParent() } span(1) { - name "GET _cluster/health" + name "GET" kind CLIENT childOf(span(0)) attributes { "$SemanticAttributes.DB_SYSTEM" "elasticsearch" - "$SemanticAttributes.DB_OPERATION" "GET _cluster/health" + "$SemanticAttributes.DB_OPERATION" "GET" + "$SemanticAttributes.DB_STATEMENT" "GET _cluster/health" "$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME" httpHost.hostName "$SemanticAttributes.NET_PEER_PORT" httpHost.port diff --git a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Singletons.java b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Singletons.java index 50e81bb6ece5..5e9a37e51bd6 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Singletons.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/ElasticsearchRest7Singletons.java @@ -7,14 +7,15 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestInstrumenterFactory; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestRequest; import org.elasticsearch.client.Response; public final class ElasticsearchRest7Singletons { - private static final Instrumenter INSTRUMENTER = + private static final Instrumenter INSTRUMENTER = ElasticsearchRestInstrumenterFactory.create("io.opentelemetry.elasticsearch-rest-7.0"); - public static Instrumenter instrumenter() { + public static Instrumenter instrumenter() { return INSTRUMENTER; } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/RestClientInstrumentation.java b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/RestClientInstrumentation.java index 476a5de26e28..0631c53a56ed 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/RestClientInstrumentation.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/v7_0/RestClientInstrumentation.java @@ -16,6 +16,7 @@ import io.opentelemetry.context.Scope; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.ElasticsearchRestRequest; import io.opentelemetry.javaagent.instrumentation.elasticsearch.rest.RestResponseListener; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; @@ -53,12 +54,12 @@ public static class PerformRequestAdvice { @Advice.OnMethodEnter(suppress = Throwable.class) public static void onEnter( @Advice.Argument(0) Request request, - @Advice.Local("otelRequest") String otelRequest, + @Advice.Local("otelRequest") ElasticsearchRestRequest otelRequest, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { Context parentContext = currentContext(); - otelRequest = request.getMethod() + " " + request.getEndpoint(); + otelRequest = ElasticsearchRestRequest.create(request.getMethod(), request.getEndpoint()); if (!instrumenter().shouldStart(parentContext, otelRequest)) { return; } @@ -71,7 +72,7 @@ public static void onEnter( public static void stopSpan( @Advice.Return(readOnly = false) Response response, @Advice.Thrown Throwable throwable, - @Advice.Local("otelRequest") String otelRequest, + @Advice.Local("otelRequest") ElasticsearchRestRequest otelRequest, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { @@ -91,12 +92,12 @@ public static class PerformRequestAsyncAdvice { public static void onEnter( @Advice.Argument(0) Request request, @Advice.Argument(value = 1, readOnly = false) ResponseListener responseListener, - @Advice.Local("otelRequest") String otelRequest, + @Advice.Local("otelRequest") ElasticsearchRestRequest otelRequest, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { Context parentContext = currentContext(); - otelRequest = request.getMethod() + " " + request.getEndpoint(); + otelRequest = ElasticsearchRestRequest.create(request.getMethod(), request.getEndpoint()); if (!instrumenter().shouldStart(parentContext, otelRequest)) { return; } @@ -112,7 +113,7 @@ public static void onEnter( @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopSpan( @Advice.Thrown Throwable throwable, - @Advice.Local("otelRequest") String otelRequest, + @Advice.Local("otelRequest") ElasticsearchRestRequest otelRequest, @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { diff --git a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy index e5aaa8ee4391..8d3d8f8820c2 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy +++ b/instrumentation/elasticsearch/elasticsearch-rest-7.0/javaagent/src/test/groovy/ElasticsearchRest7Test.groovy @@ -65,12 +65,13 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification { assertTraces(1) { trace(0, 1) { span(0) { - name "GET _cluster/health" + name "GET" kind CLIENT hasNoParent() attributes { "$SemanticAttributes.DB_SYSTEM" "elasticsearch" - "$SemanticAttributes.DB_OPERATION" "GET _cluster/health" + "$SemanticAttributes.DB_OPERATION" "GET" + "$SemanticAttributes.DB_STATEMENT" "GET _cluster/health" "$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME" httpHost.hostName "$SemanticAttributes.NET_PEER_PORT" httpHost.port @@ -123,12 +124,13 @@ class ElasticsearchRest7Test extends AgentInstrumentationSpecification { hasNoParent() } span(1) { - name "GET _cluster/health" + name "GET" kind CLIENT childOf(span(0)) attributes { "$SemanticAttributes.DB_SYSTEM" "elasticsearch" - "$SemanticAttributes.DB_OPERATION" "GET _cluster/health" + "$SemanticAttributes.DB_OPERATION" "GET" + "$SemanticAttributes.DB_STATEMENT" "GET _cluster/health" "$SemanticAttributes.NET_TRANSPORT" SemanticAttributes.NetTransportValues.IP_TCP "$SemanticAttributes.NET_PEER_NAME" httpHost.hostName "$SemanticAttributes.NET_PEER_PORT" httpHost.port diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/build.gradle.kts b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/build.gradle.kts index 9edc7f4481ee..427b317c98ba 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/build.gradle.kts +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/build.gradle.kts @@ -4,4 +4,7 @@ plugins { dependencies { compileOnly("org.elasticsearch.client:rest:5.0.0") + compileOnly("com.google.auto.value:auto-value-annotations") + + annotationProcessor("com.google.auto.value:auto-value") } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesGetter.java index bdb92b8d3156..0bb4a7eddeb6 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestAttributesGetter.java @@ -9,40 +9,41 @@ import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; -final class ElasticsearchRestAttributesGetter implements DbClientAttributesGetter { +final class ElasticsearchRestAttributesGetter + implements DbClientAttributesGetter { @Override - public String system(String operation) { + public String system(ElasticsearchRestRequest request) { return SemanticAttributes.DbSystemValues.ELASTICSEARCH; } @Override @Nullable - public String user(String operation) { + public String user(ElasticsearchRestRequest request) { return null; } @Override @Nullable - public String name(String operation) { + public String name(ElasticsearchRestRequest request) { return null; } @Override @Nullable - public String connectionString(String operation) { + public String connectionString(ElasticsearchRestRequest request) { return null; } @Override @Nullable - public String statement(String operation) { - return null; + public String statement(ElasticsearchRestRequest request) { + return request.getMethod() + " " + request.getOperation(); } @Override @Nullable - public String operation(String operation) { - return operation; + public String operation(ElasticsearchRestRequest request) { + return request.getMethod(); } } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java index e909935a6cf2..b42cd510876f 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestInstrumenterFactory.java @@ -16,13 +16,14 @@ public final class ElasticsearchRestInstrumenterFactory { - public static Instrumenter create(String instrumentationName) { + public static Instrumenter create( + String instrumentationName) { ElasticsearchRestAttributesGetter dbClientAttributesGetter = new ElasticsearchRestAttributesGetter(); ElasticsearchRestNetResponseAttributesGetter netAttributesGetter = new ElasticsearchRestNetResponseAttributesGetter(); - return Instrumenter.builder( + return Instrumenter.builder( GlobalOpenTelemetry.get(), instrumentationName, DbClientSpanNameExtractor.create(dbClientAttributesGetter)) diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java index b61a263d5adf..0b93f3f5ed56 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestNetResponseAttributesGetter.java @@ -11,16 +11,16 @@ import org.elasticsearch.client.Response; final class ElasticsearchRestNetResponseAttributesGetter - implements NetClientAttributesGetter { + implements NetClientAttributesGetter { @Override - public String transport(String operation, Response response) { + public String transport(ElasticsearchRestRequest request, Response response) { return SemanticAttributes.NetTransportValues.IP_TCP; } @Override @Nullable - public String peerName(String operation, @Nullable Response response) { + public String peerName(ElasticsearchRestRequest request, @Nullable Response response) { if (response != null) { return response.getHost().getHostName(); } @@ -29,7 +29,7 @@ public String peerName(String operation, @Nullable Response response) { @Override @Nullable - public Integer peerPort(String operation, @Nullable Response response) { + public Integer peerPort(ElasticsearchRestRequest request, @Nullable Response response) { if (response != null) { return response.getHost().getPort(); } @@ -38,7 +38,7 @@ public Integer peerPort(String operation, @Nullable Response response) { @Override @Nullable - public String peerIp(String operation, @Nullable Response response) { + public String peerIp(ElasticsearchRestRequest request, @Nullable Response response) { if (response != null && response.getHost().getAddress() != null) { return response.getHost().getAddress().getHostAddress(); } diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestRequest.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestRequest.java new file mode 100644 index 000000000000..3298c1a40dc7 --- /dev/null +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/ElasticsearchRestRequest.java @@ -0,0 +1,20 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.elasticsearch.rest; + +import com.google.auto.value.AutoValue; + +@AutoValue +public abstract class ElasticsearchRestRequest { + + public static ElasticsearchRestRequest create(String method, String endpoint) { + return new AutoValue_ElasticsearchRestRequest(method, endpoint); + } + + public abstract String getMethod(); + + public abstract String getOperation(); +} diff --git a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/RestResponseListener.java b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/RestResponseListener.java index bb95dda75713..ba29b49d57f1 100644 --- a/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/RestResponseListener.java +++ b/instrumentation/elasticsearch/elasticsearch-rest-common/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/elasticsearch/rest/RestResponseListener.java @@ -15,16 +15,16 @@ public final class RestResponseListener implements ResponseListener { private final ResponseListener listener; private final Context parentContext; - private final Instrumenter instrumenter; + private final Instrumenter instrumenter; private final Context context; - private final String request; + private final ElasticsearchRestRequest request; public RestResponseListener( ResponseListener listener, Context parentContext, - Instrumenter instrumenter, + Instrumenter instrumenter, Context context, - String request) { + ElasticsearchRestRequest request) { this.listener = listener; this.parentContext = parentContext; this.instrumenter = instrumenter;