From faf4a926d3725dac7a4a6ad463904a9f8a1b0cf9 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 9 Nov 2023 04:03:34 +0530 Subject: [PATCH 01/21] adds aerospike instrumentation --- .../api/instrumenter/db/AerospikeMetrics.java | 116 +++++++++ .../db/AerospikeMetricsAdvice.java | 158 +++++++++++++ .../db/AerospikeSemanticAttributes.java | 25 ++ .../instrumenter/db/DbMessageSizeUtil.java | 27 +++ .../javaagent/build.gradle.kts | 26 ++ .../AerospikeClientAttributeExtractor.java | 45 ++++ .../AerospikeClientInstrumentationModule.java | 45 ++++ .../v7_1/AerospikeRequest.java | 59 +++++ .../v7_1/AerospikeRequestContext.java | 49 ++++ .../v7_1/AersopikeSingletons.java | 44 ++++ .../v7_1/AsyncCommandInstrumentation.java | 85 +++++++ .../v7_1/AsyncHandlerInstrumentation.java | 95 ++++++++ .../AsyncScanAllCommandInstrumentation.java | 141 +++++++++++ .../v7_1/DbAttributesGetter.java | 44 ++++ .../v7_1/NetworkAttributesGetter.java | 27 +++ .../v7_1/SocketInstrumentation.java | 83 +++++++ .../aerospike_client/v7_1/Status.java | 7 + .../v7_1/SyncCommandInstrumentation.java | 223 ++++++++++++++++++ .../v7_1/TransferSizeIntrumentation.java | 43 ++++ .../v7_1/AerospikeClientAsyncCommandTest.java | 121 ++++++++++ .../v7_1/AerospikeClientSyncCommandTest.java | 113 +++++++++ settings.gradle.kts | 1 + 22 files changed, 1577 insertions(+) create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java create mode 100644 instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/DbAttributesGetter.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java new file mode 100644 index 000000000000..ae427940c88e --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java @@ -0,0 +1,116 @@ +package io.opentelemetry.instrumentation.api.instrumenter.db; + +import static io.opentelemetry.instrumentation.api.instrumenter.db.DbMessageSizeUtil.getMessageSize; +import static java.util.logging.Level.FINE; + +import com.google.auto.value.AutoValue; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.metrics.DoubleHistogram; +import io.opentelemetry.api.metrics.DoubleHistogramBuilder; +import io.opentelemetry.api.metrics.LongCounter; +import io.opentelemetry.api.metrics.LongCounterBuilder; +import io.opentelemetry.api.metrics.LongUpDownCounter; +import io.opentelemetry.api.metrics.LongUpDownCounterBuilder; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.ContextKey; +import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; + +public final class AerospikeMetrics implements OperationListener { + private static final double NANOS_PER_MS = TimeUnit.MILLISECONDS.toNanos(1); + + private static final ContextKey AEROSPIKE_CLIENT_METRICS_STATE = + ContextKey.named("aerospike-client-metrics-state"); + + private static final Logger logger = Logger.getLogger(AerospikeMetrics.class.getName()); + + private final LongCounter requestCounter; + private final LongCounter responseCounter; + private final LongUpDownCounter concurrencyUpDownCounter; + private final DoubleHistogram clientLatencyHistogram; + @SuppressWarnings("unused") + private final DoubleHistogram recordSizeHistogram; + + private AerospikeMetrics(Meter meter) { + LongCounterBuilder requestCounterBuilder = + meter + .counterBuilder("aerospike.requests") + .setDescription("Aerospike Calls"); + AerospikeMetricsAdvice.applyRequestCounterAdvice(requestCounterBuilder); + requestCounter = requestCounterBuilder.build(); + LongCounterBuilder responseCounterBuilder = + meter + .counterBuilder("aerospike.response") + .setDescription("Aerospike Responses"); + AerospikeMetricsAdvice.applyResponseCounterAdvice(responseCounterBuilder); + responseCounter = responseCounterBuilder.build(); + LongUpDownCounterBuilder concurrencyUpDownCounterBuilder = + meter + .upDownCounterBuilder("aerospike.concurrreny") + .setDescription("Aerospike Concurrent Requests"); + AerospikeMetricsAdvice.applyConcurrencyUpDownCounterAdvice(concurrencyUpDownCounterBuilder); + concurrencyUpDownCounter = concurrencyUpDownCounterBuilder.build(); + DoubleHistogramBuilder durationBuilder = + meter + .histogramBuilder("aerospike.client.duration") + .setDescription("Aerospike Response Latency") + .setUnit("ms"); + AerospikeMetricsAdvice.applyClientDurationAdvice(durationBuilder); + clientLatencyHistogram = durationBuilder.build(); + DoubleHistogramBuilder recordSizeHistogramBuilder = + meter + .histogramBuilder("aerospike.record.size") + .setDescription("Aerospike Record Size") + .setUnit("By"); + AerospikeMetricsAdvice.applyRecordSizeAdvice(recordSizeHistogramBuilder); + recordSizeHistogram = recordSizeHistogramBuilder.build(); + } + + public static OperationMetrics get() { + return AerospikeMetrics::new; + } + + + @Override + public Context onStart(Context context, Attributes startAttributes, long startNanos) { + requestCounter.add(1, startAttributes, context); + concurrencyUpDownCounter.add(1, startAttributes, context); + return context.with( + AEROSPIKE_CLIENT_METRICS_STATE, + new AutoValue_AerospikeMetrics_State(startAttributes, startNanos)); + } + + @Override + public void onEnd(Context context, Attributes endAttributes, long endNanos) { + State state = context.get(AEROSPIKE_CLIENT_METRICS_STATE); + if (state == null) { + logger.log( + FINE, + "No state present when ending context {0}. Cannot record Aerospike End Call metrics.", + context); + return; + } + concurrencyUpDownCounter.add(-1, state.startAttributes(), context); + Attributes mergedAttributes = state.startAttributes().toBuilder().putAll(endAttributes).build(); + responseCounter.add(1, mergedAttributes, context); + clientLatencyHistogram.record( + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, + mergedAttributes, + context); + Long requestBodySize = getMessageSize(mergedAttributes); + if (requestBodySize != null) { + recordSizeHistogram.record(requestBodySize, mergedAttributes, context); + } + } + + @AutoValue + abstract static class State { + + abstract Attributes startAttributes(); + + abstract long startTimeNanos(); + } +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java new file mode 100644 index 000000000000..b325f2b9ab2c --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java @@ -0,0 +1,158 @@ +package io.opentelemetry.instrumentation.api.instrumenter.db; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.metrics.DoubleHistogramBuilder; +import io.opentelemetry.api.metrics.LongCounterBuilder; +import io.opentelemetry.api.metrics.LongUpDownCounterBuilder; +import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder; +import io.opentelemetry.extension.incubator.metrics.ExtendedLongCounterBuilder; +import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder; +import io.opentelemetry.instrumentation.api.internal.SemconvStability; +import io.opentelemetry.semconv.SemanticAttributes; +import java.util.ArrayList; +import java.util.List; + +final class AerospikeMetricsAdvice { + private AerospikeMetricsAdvice() {} + + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 + static void applyRequestCounterAdvice(LongCounterBuilder builder) { + if (!(builder instanceof ExtendedLongCounterBuilder)) { + return; + } + + List> attributes = new ArrayList<>(); + attributes.add(SemanticAttributes.DB_SYSTEM); + attributes.add(SemanticAttributes.DB_OPERATION); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); + if (SemconvStability.emitStableHttpSemconv()) { + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); + attributes.add(SemanticAttributes.SERVER_ADDRESS); + attributes.add(SemanticAttributes.SERVER_PORT); + } + if (SemconvStability.emitOldHttpSemconv()) { + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); + } + + ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); + } + + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 + static void applyConcurrencyUpDownCounterAdvice(LongUpDownCounterBuilder builder) { + if (!(builder instanceof ExtendedLongUpDownCounterBuilder)) { + return; + } + + List> attributes = new ArrayList<>(); + attributes.add(SemanticAttributes.DB_SYSTEM); + attributes.add(SemanticAttributes.DB_OPERATION); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); + if (SemconvStability.emitStableHttpSemconv()) { + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); + attributes.add(SemanticAttributes.SERVER_ADDRESS); + attributes.add(SemanticAttributes.SERVER_PORT); + } + if (SemconvStability.emitOldHttpSemconv()) { + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); + } + + ((ExtendedLongUpDownCounterBuilder) builder).setAttributesAdvice(attributes); + } + + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 + static void applyResponseCounterAdvice(LongCounterBuilder builder) { + if (!(builder instanceof ExtendedLongCounterBuilder)) { + return; + } + + List> attributes = new ArrayList<>(); + attributes.add(SemanticAttributes.DB_SYSTEM); + attributes.add(SemanticAttributes.DB_OPERATION); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); + if (SemconvStability.emitStableHttpSemconv()) { + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); + attributes.add(SemanticAttributes.SERVER_ADDRESS); + attributes.add(SemanticAttributes.SERVER_PORT); + } + if (SemconvStability.emitOldHttpSemconv()) { + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); + } + + ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); + } + + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 + static void applyClientDurationAdvice(DoubleHistogramBuilder builder) { + if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { + return; + } + + List> attributes = new ArrayList<>(); + attributes.add(SemanticAttributes.DB_SYSTEM); + attributes.add(SemanticAttributes.DB_OPERATION); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); + if (SemconvStability.emitStableHttpSemconv()) { + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); + attributes.add(SemanticAttributes.SERVER_ADDRESS); + attributes.add(SemanticAttributes.SERVER_PORT); + } + if (SemconvStability.emitOldHttpSemconv()) { + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); + } + + ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); + } + + @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 + static void applyRecordSizeAdvice(DoubleHistogramBuilder builder) { + if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { + return; + } + + List> attributes = new ArrayList<>(); + attributes.add(SemanticAttributes.DB_SYSTEM); + attributes.add(SemanticAttributes.DB_OPERATION); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); + attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); + if (SemconvStability.emitStableHttpSemconv()) { + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(SemanticAttributes.NETWORK_TRANSPORT); + attributes.add(SemanticAttributes.SERVER_ADDRESS); + attributes.add(SemanticAttributes.SERVER_PORT); + } + if (SemconvStability.emitOldHttpSemconv()) { + attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); + attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); + attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); + } + + ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); + } +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java new file mode 100644 index 000000000000..13bea862f51e --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java @@ -0,0 +1,25 @@ +package io.opentelemetry.instrumentation.api.instrumenter.db; + +import static io.opentelemetry.api.common.AttributeKey.longKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; + +import io.opentelemetry.api.common.AttributeKey; + +public final class AerospikeSemanticAttributes { + private AerospikeSemanticAttributes() {} + + public static final AttributeKey AEROSPIKE_STATUS = stringKey("aerospike.status"); + public static final AttributeKey AEROSPIKE_ERROR_CODE = longKey("aerospike.error.code"); + public static final AttributeKey AEROSPIKE_NAMESPACE = stringKey("aerospike.namespace"); + public static final AttributeKey AEROSPIKE_SET_NAME = stringKey("aerospike.set.name"); + public static final AttributeKey AEROSPIKE_USER_KEY = stringKey("aerospike.user.key"); + public static final AttributeKey AEROSPIKE_TRANSFER_SIZE = longKey( + "aerospike.transfer.size"); + + public static final class DbSystemValues { + public static final String AEROSPIKE = "aerospike"; + + private DbSystemValues() {} + } + +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java new file mode 100644 index 000000000000..65ad0d861822 --- /dev/null +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java @@ -0,0 +1,27 @@ +package io.opentelemetry.instrumentation.api.instrumenter.db; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import javax.annotation.Nullable; + +final class DbMessageSizeUtil { + + @Nullable + static Long getMessageSize(Attributes... attributesList) { + return getAttribute(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, attributesList); + } + + @Nullable + private static T getAttribute(AttributeKey key, Attributes... attributesList) { + for (Attributes attributes : attributesList) { + T value = attributes.get(key); + if (value != null) { + return value; + } + } + return null; + } + + private DbMessageSizeUtil() {} +} + diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts new file mode 100644 index 000000000000..4a251a8971a2 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -0,0 +1,26 @@ +plugins { + id("otel.javaagent-instrumentation") +} + +muzzle { + pass { + group.set("com.aerospike") + module.set("aerospike-client") + versions.set("[7.1.0,)") + assertInverse.set(true) + } +} + +dependencies { + library("com.aerospike:aerospike-client:7.1.0") + + compileOnly("com.google.auto.value:auto-value-annotations") + annotationProcessor("com.google.auto.value:auto-value") +} + +tasks { + test { + jvmArgs("-Djava.net.preferIPv4Stack=true") + usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java new file mode 100644 index 000000000000..1392d17d7453 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java @@ -0,0 +1,45 @@ +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import com.aerospike.client.AerospikeException; +import com.aerospike.client.ResultCode; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; +import javax.annotation.Nullable; + +public class AerospikeClientAttributeExtractor implements + AttributesExtractor { + + @Override + public void onStart(AttributesBuilder attributes, Context parentContext, + AerospikeRequest aerospikeRequest) { + attributes.put( + AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, + aerospikeRequest.getNamespace()); + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, aerospikeRequest.getSet()); + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, aerospikeRequest.getUserKey()); + } + + @Override + public void onEnd(AttributesBuilder attributes, Context context, + AerospikeRequest aerospikeRequest, @Nullable Void unused, @Nullable Throwable error) { + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_STATUS, + aerospikeRequest.getStatus().name()); + if (error != null) { + if (error instanceof AerospikeException) { + AerospikeException aerospikeException = (AerospikeException) error; + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, + aerospikeException.getResultCode()); + } else { + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, ResultCode.CLIENT_ERROR); + } + } else { + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, ResultCode.OK); + if (aerospikeRequest.getSize() != null) { + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, + aerospikeRequest.getSize()); + } + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java new file mode 100644 index 000000000000..4047cca50e27 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java @@ -0,0 +1,45 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; +import static java.util.Arrays.asList; + +import com.google.auto.service.AutoService; +import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import java.util.List; +import net.bytebuddy.matcher.ElementMatcher; + +@AutoService(InstrumentationModule.class) +public class AerospikeClientInstrumentationModule extends InstrumentationModule { + + public AerospikeClientInstrumentationModule() { + super("aerospike-client", "aerospike-client-7.1.0"); + } + + @Override + public ElementMatcher.Junction classLoaderMatcher() { + return hasClassesNamed("com.aerospike.client.AerospikeClient"); + } + + @Override + public List typeInstrumentations() { + return asList( + new SyncCommandInstrumentation(), + new SocketInstrumentation(), + new TransferSizeIntrumentation(), + new AsyncCommandInstrumentation(), + new AsyncHandlerInstrumentation(), + new AsyncScanAllCommandInstrumentation() + ); + } + + @Override + public boolean isIndyModule() { + return false; + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java new file mode 100644 index 000000000000..c336471b1bd7 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java @@ -0,0 +1,59 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import com.aerospike.client.Key; +import com.aerospike.client.cluster.Node; +import com.google.auto.value.AutoValue; +import javax.annotation.Nullable; + +@AutoValue +public abstract class AerospikeRequest { + private Node node; + private Integer size; + private Status status; + + public static AerospikeRequest create(String operation, Key key) { + return new AutoValue_AerospikeRequest(operation, key.namespace, key.setName, key.userKey.toString()); + } + + public static AerospikeRequest create(String operation, String namespace, String set) { + return new AutoValue_AerospikeRequest(operation, namespace, set, null); + } + + public abstract String getOperation(); + + public abstract String getNamespace(); + + public abstract String getSet(); + + @Nullable + public abstract String getUserKey(); + + public void setNode(Node node) { + this.node = node; + } + + public Node getNode() { + return this.node; + } + + public Integer getSize() { + return size; + } + + public void setSize(Integer size) { + this.size = size; + } + + public Status getStatus() { + return status; + } + + public void setStatus(Status status) { + this.status = status; + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java new file mode 100644 index 000000000000..50636365ef0e --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java @@ -0,0 +1,49 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; + +public final class AerospikeRequestContext { + private static final ThreadLocal contextThreadLocal = new ThreadLocal<>(); + private AerospikeRequest request; + private Context context; + + private AerospikeRequestContext() {} + + public static AerospikeRequestContext attach(AerospikeRequest request, Context context) { + + AerospikeRequestContext requestContext = new AerospikeRequestContext(); + requestContext.request = request; + requestContext.context = context; + contextThreadLocal.set(requestContext); + return requestContext; + } + + public void detachAndEnd() { + contextThreadLocal.remove(); + } + + @SuppressWarnings("unchecked") + public static AerospikeRequestContext current() { + return contextThreadLocal.get(); + } + + public void endSpan( + Instrumenter instrumenter, Context context, AerospikeRequest request, + Throwable throwable) { + instrumenter.end(context, request, null, throwable); + } + + public AerospikeRequest getRequest() { + return request; + } + + public Context getContext() { + return context; + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java new file mode 100644 index 000000000000..d7c66a7e8cbd --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; +import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; + +public final class AersopikeSingletons { + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.0"; + + private static final Instrumenter INSTRUMENTER; + + static { + DbAttributesGetter dbAttributesGetter = new DbAttributesGetter(); + NetworkAttributesGetter netAttributesGetter = new NetworkAttributesGetter(); + + INSTRUMENTER = + Instrumenter.builder( + GlobalOpenTelemetry.get(), + INSTRUMENTATION_NAME, + DbClientSpanNameExtractor.create(dbAttributesGetter)) + .addAttributesExtractor(new AerospikeClientAttributeExtractor()) + .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) + .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) + .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) + .addOperationMetrics(AerospikeMetrics.get()) + .buildInstrumenter(SpanKindExtractor.alwaysClient()); + } + + public static Instrumenter instrumenter() { + return INSTRUMENTER; + } + + private AersopikeSingletons() {} +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java new file mode 100644 index 000000000000..408b057f6591 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java @@ -0,0 +1,85 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; +import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; +import static net.bytebuddy.matcher.ElementMatchers.isConstructor; +import static net.bytebuddy.matcher.ElementMatchers.isPublic; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; + +import com.aerospike.client.Key; +import com.aerospike.client.command.Command; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.Scope; +import io.opentelemetry.instrumentation.api.util.VirtualField; +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import java.util.Locale; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class AsyncCommandInstrumentation implements TypeInstrumentation { + @Override + public ElementMatcher typeMatcher() { + return hasSuperClass(named("com.aerospike.client.async.AsyncCommand").and( + not(named("com.aerospike.client.command.Command")))); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + isConstructor() + .and(isPublic()), + this.getClass().getName() + "$ConstructorAdvice"); + } + + @SuppressWarnings("unused") + public static class ConstructorAdvice { + @Advice.OnMethodExit(suppress = Throwable.class) + public static void onExit( + @Advice.This Command command, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope, + @Advice.AllArguments Object[] objects) { + Key key = null; + for (Object object : objects) { + if (object instanceof Key) { + key = (Key) object; + break; + } + } + if (key == null) { + return; + } + VirtualField virtualField = VirtualField.find(Command.class, + AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(command); + if (requestContext != null) { + return; + } + Context parentContext = currentContext(); + request = AerospikeRequest.create(command.getClass().getSimpleName().toUpperCase(Locale.ROOT), + key); + if (!instrumenter().shouldStart(parentContext, request)) { + return; + } + context = instrumenter().start(parentContext, request); + AerospikeRequestContext aerospikeRequestContext = AerospikeRequestContext.attach(request, + context); + scope = context.makeCurrent(); + + virtualField.set(command, aerospikeRequestContext); + if (scope != null) { + scope.close(); + } + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java new file mode 100644 index 000000000000..a54260cddd47 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java @@ -0,0 +1,95 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.SUCCESS; +import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; +import static net.bytebuddy.matcher.ElementMatchers.isProtected; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; + +import com.aerospike.client.command.Command; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.Scope; +import io.opentelemetry.instrumentation.api.util.VirtualField; +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class AsyncHandlerInstrumentation implements TypeInstrumentation { + + @Override + public ElementMatcher typeMatcher() { + return hasSuperClass(named("com.aerospike.client.command.Command")); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + named("onSuccess") + .and(takesNoArguments()) + .and(isProtected()), + this.getClass().getName() + "$OnSuccessAdvice"); + transformer.applyAdviceToMethod( + named("onFailure") + .and(takesArgument(0, named("com.aerospike.client.AerospikeException"))) + .and(isProtected()), + this.getClass().getName() + "$OnFailureAdvice"); + } + + @SuppressWarnings("unused") + public static class OnSuccessAdvice { + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Command command) { + VirtualField virtualField = VirtualField.find(Command.class, + AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(command); + virtualField.set(command, null); + if (requestContext != null) { + AerospikeRequest request = requestContext.getRequest(); + Context context = requestContext.getContext(); + if (throwable == null) { + request.setStatus(SUCCESS); + } else { + request.setStatus(FAILURE); + } + requestContext.endSpan(instrumenter(), context, request, throwable); + Scope scope = context.makeCurrent(); + if (null != scope) { + scope.close(); + } + } + } + } + + @SuppressWarnings("unused") + public static class OnFailureAdvice { + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Command command) { + VirtualField virtualField = VirtualField.find(Command.class, + AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(command); + virtualField.set(command, null); + if (requestContext != null) { + AerospikeRequest request = requestContext.getRequest(); + Context context = requestContext.getContext(); + request.setStatus(FAILURE); + requestContext.endSpan(instrumenter(), context, request, throwable); + Scope scope = context.makeCurrent(); + if (null != scope) { + scope.close(); + } + } + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java new file mode 100644 index 000000000000..a1291f9b6d8d --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java @@ -0,0 +1,141 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.SUCCESS; +import static net.bytebuddy.matcher.ElementMatchers.isConstructor; +import static net.bytebuddy.matcher.ElementMatchers.isProtected; +import static net.bytebuddy.matcher.ElementMatchers.isPublic; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; + +import com.aerospike.client.async.AsyncScanPartitionExecutor; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.Scope; +import io.opentelemetry.instrumentation.api.util.VirtualField; +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import java.util.Locale; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class AsyncScanAllCommandInstrumentation implements TypeInstrumentation { + @Override + public ElementMatcher typeMatcher() { + return named("com.aerospike.client.async.AsyncScanPartitionExecutor"); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + isConstructor() + .and(isPublic()), + this.getClass().getName() + "$ConstructorAdvice"); + transformer.applyAdviceToMethod( + named("onSuccess") + .and(takesNoArguments()) + .and(isProtected()), + this.getClass().getName() + "$OnSuccessAdvice"); + transformer.applyAdviceToMethod( + named("onFailure") + .and(takesArgument(0, named("com.aerospike.client.AerospikeException"))) + .and(isProtected()), + this.getClass().getName() + "$OnFailureAdvice"); + } + + @SuppressWarnings("unused") + public static class ConstructorAdvice { + @Advice.OnMethodExit(suppress = Throwable.class) + public static void onExit( + @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope, + @Advice.Argument(4) String namespace, + @Advice.Argument(5) String setName) { + VirtualField virtualField = VirtualField.find( + AsyncScanPartitionExecutor.class, + AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); + if (requestContext != null) { + return; + } + Context parentContext = currentContext(); + request = AerospikeRequest.create( + asyncScanPartitionExecutor.getClass().getSimpleName().toUpperCase(Locale.ROOT), + namespace, setName); + if (!instrumenter().shouldStart(parentContext, request)) { + return; + } + context = instrumenter().start(parentContext, request); + AerospikeRequestContext aerospikeRequestContext = AerospikeRequestContext.attach(request, + context); + scope = context.makeCurrent(); + + virtualField.set(asyncScanPartitionExecutor, aerospikeRequestContext); + if (scope != null) { + scope.close(); + } + } + } + + @SuppressWarnings("unused") + public static class OnSuccessAdvice { + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void onExit(@Advice.Thrown Throwable throwable, + @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor) { + VirtualField virtualField = VirtualField.find( + AsyncScanPartitionExecutor.class, + AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); + virtualField.set(asyncScanPartitionExecutor, null); + if (requestContext != null) { + AerospikeRequest request = requestContext.getRequest(); + Context context = requestContext.getContext(); + if (throwable == null) { + request.setStatus(SUCCESS); + } else { + request.setStatus(FAILURE); + } + requestContext.endSpan(instrumenter(), context, request, throwable); + Scope scope = context.makeCurrent(); + if (null != scope) { + scope.close(); + } + } + } + } + + @SuppressWarnings("unused") + public static class OnFailureAdvice { + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void onExit(@Advice.Thrown Throwable throwable, + @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor) { + VirtualField virtualField = VirtualField.find( + AsyncScanPartitionExecutor.class, + AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); + virtualField.set(asyncScanPartitionExecutor, null); + if (requestContext != null) { + AerospikeRequest request = requestContext.getRequest(); + Context context = requestContext.getContext(); + request.setStatus(FAILURE); + requestContext.endSpan(instrumenter(), context, request, throwable); + Scope scope = context.makeCurrent(); + if (null != scope) { + scope.close(); + } + } + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/DbAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/DbAttributesGetter.java new file mode 100644 index 000000000000..08664a5a0577 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/DbAttributesGetter.java @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; +import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesGetter; +import javax.annotation.Nullable; + +final class DbAttributesGetter implements DbClientAttributesGetter { + + @Override + public String getSystem(AerospikeRequest request) { + return AerospikeSemanticAttributes.DbSystemValues.AEROSPIKE; + } + + @Override + @Nullable + public String getUser(AerospikeRequest request) { + return null; + } + + @Override + public String getName(AerospikeRequest request) { + return null; + } + + @Override + public String getConnectionString(AerospikeRequest request) { + return null; + } + + @Override + public String getStatement(AerospikeRequest request) { + return null; + } + + @Override + public String getOperation(AerospikeRequest request) { + return request.getOperation(); + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java new file mode 100644 index 000000000000..645dfcdcdd51 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java @@ -0,0 +1,27 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import com.aerospike.client.cluster.Node; +import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import java.net.InetSocketAddress; +import javax.annotation.Nullable; + +final class NetworkAttributesGetter implements + ServerAttributesGetter, + io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter { + + @Override + @Nullable + public InetSocketAddress getNetworkPeerInetSocketAddress(AerospikeRequest aerospikeRequest, + @Nullable Void unused) { + Node node = aerospikeRequest.getNode(); + if (node != null) { + return node.getAddress(); + } + return null; + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java new file mode 100644 index 000000000000..6cb0cfd2848d --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java @@ -0,0 +1,83 @@ +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; +import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; +import static net.bytebuddy.matcher.ElementMatchers.isMethod; +import static net.bytebuddy.matcher.ElementMatchers.isProtected; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.returns; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; +import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; + +import com.aerospike.client.cluster.Node; +import com.aerospike.client.command.Command; +import io.opentelemetry.instrumentation.api.util.VirtualField; +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class SocketInstrumentation implements TypeInstrumentation { + + @Override + public ElementMatcher typeMatcher() { + return hasSuperClass(named("com.aerospike.client.command.Command")); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + isMethod() + .and(isProtected()) + .and(named("getNode")) + .and(returns(named("com.aerospike.client.cluster.Node"))) + .and(takesNoArguments()), + this.getClass().getName() + "$NodeSyncCommandAdvice"); + + transformer.applyAdviceToMethod( + isMethod() + .and(named("getNode")) + .and(returns(named("com.aerospike.client.cluster.Node"))) + .and(takesArgument(0, named("com.aerospike.client.cluster.Cluster"))), + this.getClass().getName() + "$NodeAsyncCommandAdvice"); + } + + @SuppressWarnings("unused") + public static class NodeSyncCommandAdvice { + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void stopSpan( + @Advice.Return Node node) { + AerospikeRequestContext context = AerospikeRequestContext.current(); + if (context != null) { + AerospikeRequest request = context.getRequest(); + request.setNode(node); + } + } + } + + @SuppressWarnings("unused") + public static class NodeAsyncCommandAdvice { + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void stopSpan( + @Advice.Thrown Throwable throwable, + @Advice.Return Node node, + @Advice.This Command command) { + VirtualField virtualField = VirtualField.find(Command.class, + AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(command); + if (requestContext != null) { + AerospikeRequest request = requestContext.getRequest(); + request.setNode(node); + if (throwable != null) { + request.setStatus(FAILURE); + requestContext.endSpan(instrumenter(), requestContext.getContext(), request, throwable); + requestContext.detachAndEnd(); + } + } + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java new file mode 100644 index 000000000000..19993fa54062 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java @@ -0,0 +1,7 @@ +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +public enum Status { + SUCCESS, + FAILURE, + RECORD_NOT_FOUND; +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java new file mode 100644 index 000000000000..c219315b6ca3 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java @@ -0,0 +1,223 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.RECORD_NOT_FOUND; +import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.SUCCESS; +import static net.bytebuddy.matcher.ElementMatchers.isFinal; +import static net.bytebuddy.matcher.ElementMatchers.isMethod; +import static net.bytebuddy.matcher.ElementMatchers.isPublic; +import static net.bytebuddy.matcher.ElementMatchers.isStatic; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; +import static net.bytebuddy.matcher.ElementMatchers.returns; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; + +import com.aerospike.client.Key; +import com.aerospike.client.Record; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.Scope; +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import java.util.Locale; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class SyncCommandInstrumentation implements TypeInstrumentation { + @Override + public ElementMatcher typeMatcher() { + return named("com.aerospike.client.AerospikeClient"); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + isMethod() + .and(isPublic()) + .and(not(isStatic())).and(isFinal()) + .and(takesArgument(1, named("com.aerospike.client.Key"))) + .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))) + .and(returns(named("com.aerospike.client.Record"))), + this.getClass().getName() + "$SyncReturnCommandAdvice"); + + transformer.applyAdviceToMethod( + isMethod() + .and(isPublic()) + .and(not(isStatic())).and(isFinal()) + .and(takesArgument(1, named("com.aerospike.client.Key"))) + .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))) + .and(not(returns(named("com.aerospike.client.Record")))), + this.getClass().getName() + "$SyncNonReturnCommandAdvice"); + + transformer.applyAdviceToMethod( + isMethod() + .and(isPublic()) + .and(not(isStatic())).and(isFinal()).and(named("scanAll")) + .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))), + this.getClass().getName() + "$SyncScanAllCommandAdvice"); + } + + @SuppressWarnings("unused") + public static class SyncReturnCommandAdvice { + + @Advice.OnMethodEnter(suppress = Throwable.class) + public static AerospikeRequestContext onEnter( + @Advice.Origin("#m") String methodName, + @Advice.AllArguments Object[] keys, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope) { + Context parentContext = currentContext(); + Key key = null; + for (Object object : keys) { + if (object instanceof Key) { + key = (Key) object; + } + } + if (key == null) { + return null; + } + request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key); + if (!instrumenter().shouldStart(parentContext, request)) { + return null; + } + context = instrumenter().start(parentContext, request); + scope = context.makeCurrent(); + return AerospikeRequestContext.attach(request, context); + } + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void stopSpan( + @Advice.Return Record record, + @Advice.Thrown Throwable throwable, + @Advice.Enter AerospikeRequestContext requestContext, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope) { + if (throwable != null) { + request.setStatus(FAILURE); + } else if (record == null) { + request.setStatus(RECORD_NOT_FOUND); + } else { + request.setStatus(SUCCESS); + } + if (scope == null) { + return; + } + + scope.close(); + if (requestContext != null) { + requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.detachAndEnd(); + } + } + } + + @SuppressWarnings("unused") + public static class SyncNonReturnCommandAdvice { + + @Advice.OnMethodEnter(suppress = Throwable.class) + public static AerospikeRequestContext onEnter( + @Advice.Origin("#m") String methodName, + @Advice.AllArguments Object[] keys, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope) { + Context parentContext = currentContext(); + Key key = null; + for (Object object : keys) { + if (object instanceof Key) { + key = (Key) object; + } + } + if (key == null) { + return null; + } + request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key); + if (!instrumenter().shouldStart(parentContext, request)) { + return null; + } + context = instrumenter().start(parentContext, request); + scope = context.makeCurrent(); + return AerospikeRequestContext.attach(request, context); + } + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static AerospikeRequestContext stopSpan( + @Advice.Thrown Throwable throwable, + @Advice.Enter AerospikeRequestContext requestContext, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope) { + if (throwable != null) { + request.setStatus(FAILURE); + } else { + request.setStatus(SUCCESS); + } + if (scope == null) { + return requestContext; + } + + scope.close(); + if (requestContext != null) { + requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.detachAndEnd(); + } + return requestContext; + } + } + + @SuppressWarnings("unused") + public static class SyncScanAllCommandAdvice { + + @Advice.OnMethodEnter(suppress = Throwable.class) + public static AerospikeRequestContext onEnter( + @Advice.Origin("#m") String methodName, + @Advice.Argument(1) String namespace, + @Advice.Argument(2) String setName, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope) { + Context parentContext = currentContext(); + + request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), namespace, setName); + if (!instrumenter().shouldStart(parentContext, request)) { + return null; + } + context = instrumenter().start(parentContext, request); + scope = context.makeCurrent(); + return AerospikeRequestContext.attach(request, context); + } + + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static AerospikeRequestContext stopSpan( + @Advice.Thrown Throwable throwable, + @Advice.Enter AerospikeRequestContext requestContext, + @Advice.Local("otelAerospikeRequest") AerospikeRequest request, + @Advice.Local("otelContext") Context context, + @Advice.Local("otelScope") Scope scope) { + if (throwable != null) { + request.setStatus(FAILURE); + } else { + request.setStatus(SUCCESS); + } + if (scope == null) { + return requestContext; + } + + scope.close(); + if (requestContext != null) { + requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.detachAndEnd(); + } + return requestContext; + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java new file mode 100644 index 000000000000..53a9eb6c14b4 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java @@ -0,0 +1,43 @@ +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; +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.takesNoArguments; + +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class TransferSizeIntrumentation implements TypeInstrumentation { + @Override + public ElementMatcher typeMatcher() { + return hasSuperClass(named("com.aerospike.client.command.Command")); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + isMethod() + .and(isPublic()) + .and(named("execute")) + .and(takesNoArguments()), + this.getClass().getName() + "$SizeAdvice"); + } + + @SuppressWarnings("unused") + public static class SizeAdvice { + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) + public static void stopSpan( + @Advice.FieldValue("dataOffset") int dataOffset) { + AerospikeRequestContext context = AerospikeRequestContext.current(); + if (context != null) { + AerospikeRequest request = context.getRequest(); + request.setSize(dataOffset); + } + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java new file mode 100644 index 000000000000..2df1de9e8c0a --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java @@ -0,0 +1,121 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; +import static java.util.Collections.singletonList; + +import com.aerospike.client.AerospikeClient; +import com.aerospike.client.Bin; +import com.aerospike.client.Key; +import com.aerospike.client.async.EventLoops; +import com.aerospike.client.async.EventPolicy; +import com.aerospike.client.async.NioEventLoops; +import com.aerospike.client.policy.ClientPolicy; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.semconv.SemanticAttributes; +import java.util.List; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.testcontainers.containers.GenericContainer; + +@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 +class AerospikeClientAsyncCommandTest { + @RegisterExtension + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + static GenericContainer aerospikeServer = + new GenericContainer<>("aerospike/aerospike-server:6.2.0.0").withExposedPorts(3000); + + static int port; + + static AerospikeClient aerospikeClient; + + @BeforeAll + static void setupSpec() { + aerospikeServer.start(); + port = aerospikeServer.getMappedPort(3000); + ClientPolicy clientPolicy = new ClientPolicy(); + int eventLoopSize = Runtime.getRuntime().availableProcessors(); + EventPolicy eventPolicy = new EventPolicy(); + eventPolicy.commandsPerEventLoop = 2; + EventLoops eventLoops = new NioEventLoops(eventPolicy, eventLoopSize); + clientPolicy.eventLoops = eventLoops; + clientPolicy.maxConnsPerNode = 11; + clientPolicy.failIfNotConnected = true; + aerospikeClient = new AerospikeClient(clientPolicy, "localhost", port); + } + + @AfterAll + static void cleanupSpec() { + aerospikeClient.close(); + } + + @BeforeEach + void setup() { + testing.clearData(); + } + + @Test + void putCommand() { + Key aerospikeKey = new Key("test", "test-set", "data1"); + aerospikeClient.put(null, null, null, aerospikeKey, new Bin("bin1", "value1")); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("ASYNCWRITE") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1"))))); + } + + @Test + void getCommand() { + Key aerospikeKey = new Key("test", "test-set", "data1"); + List bins = singletonList("bin1"); + aerospikeClient.get(null, null, null, aerospikeKey, bins.toArray(new String[0])); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("ASYNCREAD") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "ASYNCREAD"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1"))))); + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java new file mode 100644 index 000000000000..6c2349f5b647 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java @@ -0,0 +1,113 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; + +import com.aerospike.client.AerospikeClient; +import com.aerospike.client.Bin; +import com.aerospike.client.Key; +import com.aerospike.client.Record; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.semconv.SemanticAttributes; +import java.util.List; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.testcontainers.containers.GenericContainer; + +@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 +class AerospikeClientSyncCommandTest { + @RegisterExtension + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + static GenericContainer aerospikeServer = + new GenericContainer<>("aerospike/aerospike-server:6.2.0.0").withExposedPorts(3000); + static int port; + + static AerospikeClient aerospikeClient; + + @BeforeAll + static void setupSpec() { + aerospikeServer.start(); + port = aerospikeServer.getMappedPort(3000); + aerospikeClient = new AerospikeClient("localhost", port); + } + + @AfterAll + static void cleanupSpec() { + aerospikeClient.close(); + } + + @BeforeEach + void setup() { + testing.clearData(); + } + + @Test + void putCommand() { + Key aerospikeKey = new Key("test", "test-set", "data1"); + aerospikeClient.put(null, aerospikeKey, new Bin("bin1", "value1")); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("PUT") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "PUT"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 95), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1"))))); + } + + @Test + void getCommand() { + Key aerospikeKey = new Key("test", "test-set", "data1"); + List bins = singletonList("bin1"); + Record aerospikeRecord = aerospikeClient.get(null, aerospikeKey, bins.toArray(new String[0])); + assertThat(aerospikeRecord.getString("bin1")).isEqualTo("value1"); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("GET") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 40), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1"))))); + } +} diff --git a/settings.gradle.kts b/settings.gradle.kts index caa039da5706..54e67de7c950 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -138,6 +138,7 @@ include(":smoke-tests:images:spring-boot") include(":smoke-tests-otel-starter") +include(":instrumentation:aerospike-client:aerospike-client-7.1:javaagent") include(":instrumentation:akka:akka-actor-2.3:javaagent") include(":instrumentation:akka:akka-actor-fork-join-2.5:javaagent") include(":instrumentation:akka:akka-http-10.0:javaagent") From a03903cc57b7b0ebcc749a4dfc05c430bfc8de9c Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 9 Nov 2023 04:07:23 +0530 Subject: [PATCH 02/21] minor refactoring and adds testInstrumentation --- .../api/instrumenter/db/AerospikeMetrics.java | 19 ++++----- .../db/AerospikeMetricsAdvice.java | 5 +++ .../db/AerospikeSemanticAttributes.java | 10 +++-- .../instrumenter/db/DbMessageSizeUtil.java | 6 ++- .../javaagent/build.gradle.kts | 1 + .../AerospikeClientAttributeExtractor.java | 36 +++++++++------- .../AerospikeClientInstrumentationModule.java | 3 +- .../v7_1/AerospikeRequest.java | 3 +- .../v7_1/AerospikeRequestContext.java | 7 +++- .../v7_1/AsyncCommandInstrumentation.java | 21 +++++----- .../v7_1/AsyncHandlerInstrumentation.java | 12 +++--- .../AsyncScanAllCommandInstrumentation.java | 41 +++++++++---------- .../v7_1/NetworkAttributesGetter.java | 11 ++--- .../v7_1/SocketInstrumentation.java | 12 ++++-- .../aerospike_client/v7_1/Status.java | 5 +++ .../v7_1/SyncCommandInstrumentation.java | 10 +++-- .../v7_1/TransferSizeIntrumentation.java | 13 +++--- 17 files changed, 124 insertions(+), 91 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java index ae427940c88e..a8e0e5c7991f 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.api.instrumenter.db; import static io.opentelemetry.instrumentation.api.instrumenter.db.DbMessageSizeUtil.getMessageSize; @@ -31,20 +36,17 @@ public final class AerospikeMetrics implements OperationListener { private final LongCounter responseCounter; private final LongUpDownCounter concurrencyUpDownCounter; private final DoubleHistogram clientLatencyHistogram; + @SuppressWarnings("unused") private final DoubleHistogram recordSizeHistogram; private AerospikeMetrics(Meter meter) { LongCounterBuilder requestCounterBuilder = - meter - .counterBuilder("aerospike.requests") - .setDescription("Aerospike Calls"); + meter.counterBuilder("aerospike.requests").setDescription("Aerospike Calls"); AerospikeMetricsAdvice.applyRequestCounterAdvice(requestCounterBuilder); requestCounter = requestCounterBuilder.build(); LongCounterBuilder responseCounterBuilder = - meter - .counterBuilder("aerospike.response") - .setDescription("Aerospike Responses"); + meter.counterBuilder("aerospike.response").setDescription("Aerospike Responses"); AerospikeMetricsAdvice.applyResponseCounterAdvice(responseCounterBuilder); responseCounter = responseCounterBuilder.build(); LongUpDownCounterBuilder concurrencyUpDownCounterBuilder = @@ -73,7 +75,6 @@ public static OperationMetrics get() { return AerospikeMetrics::new; } - @Override public Context onStart(Context context, Attributes startAttributes, long startNanos) { requestCounter.add(1, startAttributes, context); @@ -97,9 +98,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes mergedAttributes = state.startAttributes().toBuilder().putAll(endAttributes).build(); responseCounter.add(1, mergedAttributes, context); clientLatencyHistogram.record( - (endNanos - state.startTimeNanos()) / NANOS_PER_MS, - mergedAttributes, - context); + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, mergedAttributes, context); Long requestBodySize = getMessageSize(mergedAttributes); if (requestBodySize != null) { recordSizeHistogram.record(requestBodySize, mergedAttributes, context); diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java index b325f2b9ab2c..24f604332c31 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.api.instrumenter.db; import io.opentelemetry.api.common.AttributeKey; diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java index 13bea862f51e..66eb05161309 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.api.instrumenter.db; import static io.opentelemetry.api.common.AttributeKey.longKey; @@ -13,13 +18,12 @@ private AerospikeSemanticAttributes() {} public static final AttributeKey AEROSPIKE_NAMESPACE = stringKey("aerospike.namespace"); public static final AttributeKey AEROSPIKE_SET_NAME = stringKey("aerospike.set.name"); public static final AttributeKey AEROSPIKE_USER_KEY = stringKey("aerospike.user.key"); - public static final AttributeKey AEROSPIKE_TRANSFER_SIZE = longKey( - "aerospike.transfer.size"); + public static final AttributeKey AEROSPIKE_TRANSFER_SIZE = + longKey("aerospike.transfer.size"); public static final class DbSystemValues { public static final String AEROSPIKE = "aerospike"; private DbSystemValues() {} } - } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java index 65ad0d861822..cd27a32fda45 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.instrumentation.api.instrumenter.db; import io.opentelemetry.api.common.AttributeKey; @@ -24,4 +29,3 @@ private static T getAttribute(AttributeKey key, Attributes... attributesL private DbMessageSizeUtil() {} } - diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index 4a251a8971a2..5921a95c8d98 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") + testInstrumentation(project(":instrumentation:aerospike-client:aerospike-client-7.1:javaagent")) } tasks { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java index 1392d17d7453..1af35170fe25 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; import com.aerospike.client.AerospikeException; @@ -8,37 +13,40 @@ import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; import javax.annotation.Nullable; -public class AerospikeClientAttributeExtractor implements - AttributesExtractor { +public class AerospikeClientAttributeExtractor + implements AttributesExtractor { @Override - public void onStart(AttributesBuilder attributes, Context parentContext, - AerospikeRequest aerospikeRequest) { + public void onStart( + AttributesBuilder attributes, Context parentContext, AerospikeRequest aerospikeRequest) { attributes.put( - AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, - aerospikeRequest.getNamespace()); + AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, aerospikeRequest.getNamespace()); attributes.put(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, aerospikeRequest.getSet()); attributes.put(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, aerospikeRequest.getUserKey()); } @Override - public void onEnd(AttributesBuilder attributes, Context context, - AerospikeRequest aerospikeRequest, @Nullable Void unused, @Nullable Throwable error) { - attributes.put(AerospikeSemanticAttributes.AEROSPIKE_STATUS, - aerospikeRequest.getStatus().name()); + public void onEnd( + AttributesBuilder attributes, + Context context, + AerospikeRequest aerospikeRequest, + @Nullable Void unused, + @Nullable Throwable error) { + attributes.put( + AerospikeSemanticAttributes.AEROSPIKE_STATUS, aerospikeRequest.getStatus().name()); if (error != null) { if (error instanceof AerospikeException) { AerospikeException aerospikeException = (AerospikeException) error; - attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, - aerospikeException.getResultCode()); + attributes.put( + AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, aerospikeException.getResultCode()); } else { attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, ResultCode.CLIENT_ERROR); } } else { attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, ResultCode.OK); if (aerospikeRequest.getSize() != null) { - attributes.put(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, - aerospikeRequest.getSize()); + attributes.put( + AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, aerospikeRequest.getSize()); } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java index 4047cca50e27..ccd487eef554 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java @@ -34,8 +34,7 @@ public List typeInstrumentations() { new TransferSizeIntrumentation(), new AsyncCommandInstrumentation(), new AsyncHandlerInstrumentation(), - new AsyncScanAllCommandInstrumentation() - ); + new AsyncScanAllCommandInstrumentation()); } @Override diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java index c336471b1bd7..1436e7f928d7 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java @@ -17,7 +17,8 @@ public abstract class AerospikeRequest { private Status status; public static AerospikeRequest create(String operation, Key key) { - return new AutoValue_AerospikeRequest(operation, key.namespace, key.setName, key.userKey.toString()); + return new AutoValue_AerospikeRequest( + operation, key.namespace, key.setName, key.userKey.toString()); } public static AerospikeRequest create(String operation, String namespace, String set) { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java index 50636365ef0e..1631855dec2b 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java @@ -9,7 +9,8 @@ import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; public final class AerospikeRequestContext { - private static final ThreadLocal contextThreadLocal = new ThreadLocal<>(); + private static final ThreadLocal contextThreadLocal = + new ThreadLocal<>(); private AerospikeRequest request; private Context context; @@ -34,7 +35,9 @@ public static AerospikeRequestContext current() { } public void endSpan( - Instrumenter instrumenter, Context context, AerospikeRequest request, + Instrumenter instrumenter, + Context context, + AerospikeRequest request, Throwable throwable) { instrumenter.end(context, request, null, throwable); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java index 408b057f6591..eb6bdb5351cc 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java @@ -28,16 +28,15 @@ public class AsyncCommandInstrumentation implements TypeInstrumentation { @Override public ElementMatcher typeMatcher() { - return hasSuperClass(named("com.aerospike.client.async.AsyncCommand").and( - not(named("com.aerospike.client.command.Command")))); + return hasSuperClass( + named("com.aerospike.client.async.AsyncCommand") + .and(not(named("com.aerospike.client.command.Command")))); } @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - isConstructor() - .and(isPublic()), - this.getClass().getName() + "$ConstructorAdvice"); + isConstructor().and(isPublic()), this.getClass().getName() + "$ConstructorAdvice"); } @SuppressWarnings("unused") @@ -59,21 +58,21 @@ public static void onExit( if (key == null) { return; } - VirtualField virtualField = VirtualField.find(Command.class, - AerospikeRequestContext.class); + VirtualField virtualField = + VirtualField.find(Command.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(command); if (requestContext != null) { return; } Context parentContext = currentContext(); - request = AerospikeRequest.create(command.getClass().getSimpleName().toUpperCase(Locale.ROOT), - key); + request = + AerospikeRequest.create(command.getClass().getSimpleName().toUpperCase(Locale.ROOT), key); if (!instrumenter().shouldStart(parentContext, request)) { return; } context = instrumenter().start(parentContext, request); - AerospikeRequestContext aerospikeRequestContext = AerospikeRequestContext.attach(request, - context); + AerospikeRequestContext aerospikeRequestContext = + AerospikeRequestContext.attach(request, context); scope = context.makeCurrent(); virtualField.set(command, aerospikeRequestContext); diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java index a54260cddd47..e4a3262936be 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java @@ -34,9 +34,7 @@ public ElementMatcher typeMatcher() { @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - named("onSuccess") - .and(takesNoArguments()) - .and(isProtected()), + named("onSuccess").and(takesNoArguments()).and(isProtected()), this.getClass().getName() + "$OnSuccessAdvice"); transformer.applyAdviceToMethod( named("onFailure") @@ -50,8 +48,8 @@ public static class OnSuccessAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Command command) { - VirtualField virtualField = VirtualField.find(Command.class, - AerospikeRequestContext.class); + VirtualField virtualField = + VirtualField.find(Command.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(command); virtualField.set(command, null); if (requestContext != null) { @@ -76,8 +74,8 @@ public static class OnFailureAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Command command) { - VirtualField virtualField = VirtualField.find(Command.class, - AerospikeRequestContext.class); + VirtualField virtualField = + VirtualField.find(Command.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(command); virtualField.set(command, null); if (requestContext != null) { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java index a1291f9b6d8d..d728c9ed83d2 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java @@ -36,13 +36,9 @@ public ElementMatcher typeMatcher() { @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - isConstructor() - .and(isPublic()), - this.getClass().getName() + "$ConstructorAdvice"); + isConstructor().and(isPublic()), this.getClass().getName() + "$ConstructorAdvice"); transformer.applyAdviceToMethod( - named("onSuccess") - .and(takesNoArguments()) - .and(isProtected()), + named("onSuccess").and(takesNoArguments()).and(isProtected()), this.getClass().getName() + "$OnSuccessAdvice"); transformer.applyAdviceToMethod( named("onFailure") @@ -61,23 +57,24 @@ public static void onExit( @Advice.Local("otelScope") Scope scope, @Advice.Argument(4) String namespace, @Advice.Argument(5) String setName) { - VirtualField virtualField = VirtualField.find( - AsyncScanPartitionExecutor.class, - AerospikeRequestContext.class); + VirtualField virtualField = + VirtualField.find(AsyncScanPartitionExecutor.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); if (requestContext != null) { return; } Context parentContext = currentContext(); - request = AerospikeRequest.create( - asyncScanPartitionExecutor.getClass().getSimpleName().toUpperCase(Locale.ROOT), - namespace, setName); + request = + AerospikeRequest.create( + asyncScanPartitionExecutor.getClass().getSimpleName().toUpperCase(Locale.ROOT), + namespace, + setName); if (!instrumenter().shouldStart(parentContext, request)) { return; } context = instrumenter().start(parentContext, request); - AerospikeRequestContext aerospikeRequestContext = AerospikeRequestContext.attach(request, - context); + AerospikeRequestContext aerospikeRequestContext = + AerospikeRequestContext.attach(request, context); scope = context.makeCurrent(); virtualField.set(asyncScanPartitionExecutor, aerospikeRequestContext); @@ -91,11 +88,11 @@ public static void onExit( public static class OnSuccessAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void onExit(@Advice.Thrown Throwable throwable, + public static void onExit( + @Advice.Thrown Throwable throwable, @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor) { - VirtualField virtualField = VirtualField.find( - AsyncScanPartitionExecutor.class, - AerospikeRequestContext.class); + VirtualField virtualField = + VirtualField.find(AsyncScanPartitionExecutor.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); virtualField.set(asyncScanPartitionExecutor, null); if (requestContext != null) { @@ -119,11 +116,11 @@ public static void onExit(@Advice.Thrown Throwable throwable, public static class OnFailureAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void onExit(@Advice.Thrown Throwable throwable, + public static void onExit( + @Advice.Thrown Throwable throwable, @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor) { - VirtualField virtualField = VirtualField.find( - AsyncScanPartitionExecutor.class, - AerospikeRequestContext.class); + VirtualField virtualField = + VirtualField.find(AsyncScanPartitionExecutor.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); virtualField.set(asyncScanPartitionExecutor, null); if (requestContext != null) { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java index 645dfcdcdd51..5503e9e23ab1 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java @@ -10,14 +10,15 @@ import java.net.InetSocketAddress; import javax.annotation.Nullable; -final class NetworkAttributesGetter implements - ServerAttributesGetter, - io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter { +final class NetworkAttributesGetter + implements ServerAttributesGetter, + io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter< + AerospikeRequest, Void> { @Override @Nullable - public InetSocketAddress getNetworkPeerInetSocketAddress(AerospikeRequest aerospikeRequest, - @Nullable Void unused) { + public InetSocketAddress getNetworkPeerInetSocketAddress( + AerospikeRequest aerospikeRequest, @Nullable Void unused) { Node node = aerospikeRequest.getNode(); if (node != null) { return node.getAddress(); diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java index 6cb0cfd2848d..c8ce10c5ab52 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; @@ -48,8 +53,7 @@ public void transform(TypeTransformer transformer) { public static class NodeSyncCommandAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan( - @Advice.Return Node node) { + public static void stopSpan(@Advice.Return Node node) { AerospikeRequestContext context = AerospikeRequestContext.current(); if (context != null) { AerospikeRequest request = context.getRequest(); @@ -66,8 +70,8 @@ public static void stopSpan( @Advice.Thrown Throwable throwable, @Advice.Return Node node, @Advice.This Command command) { - VirtualField virtualField = VirtualField.find(Command.class, - AerospikeRequestContext.class); + VirtualField virtualField = + VirtualField.find(Command.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(command); if (requestContext != null) { AerospikeRequest request = requestContext.getRequest(); diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java index 19993fa54062..df1451836a47 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; public enum Status { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java index c219315b6ca3..d075ec76462e 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java @@ -41,7 +41,8 @@ public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( isMethod() .and(isPublic()) - .and(not(isStatic())).and(isFinal()) + .and(not(isStatic())) + .and(isFinal()) .and(takesArgument(1, named("com.aerospike.client.Key"))) .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))) .and(returns(named("com.aerospike.client.Record"))), @@ -50,7 +51,8 @@ public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( isMethod() .and(isPublic()) - .and(not(isStatic())).and(isFinal()) + .and(not(isStatic())) + .and(isFinal()) .and(takesArgument(1, named("com.aerospike.client.Key"))) .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))) .and(not(returns(named("com.aerospike.client.Record")))), @@ -59,7 +61,9 @@ public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( isMethod() .and(isPublic()) - .and(not(isStatic())).and(isFinal()).and(named("scanAll")) + .and(not(isStatic())) + .and(isFinal()) + .and(named("scanAll")) .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))), this.getClass().getName() + "$SyncScanAllCommandAdvice"); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java index 53a9eb6c14b4..bd0a4f6fd43c 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java @@ -1,3 +1,8 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; @@ -21,18 +26,14 @@ public ElementMatcher typeMatcher() { @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - isMethod() - .and(isPublic()) - .and(named("execute")) - .and(takesNoArguments()), + isMethod().and(isPublic()).and(named("execute")).and(takesNoArguments()), this.getClass().getName() + "$SizeAdvice"); } @SuppressWarnings("unused") public static class SizeAdvice { @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan( - @Advice.FieldValue("dataOffset") int dataOffset) { + public static void stopSpan(@Advice.FieldValue("dataOffset") int dataOffset) { AerospikeRequestContext context = AerospikeRequestContext.current(); if (context != null) { AerospikeRequest request = context.getRequest(); From ecdd74724ccd981667bf6ced9e6117e3064170eb Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 10 Nov 2023 04:12:34 +0530 Subject: [PATCH 03/21] changes muzzle fail and test case container startup check --- .../javaagent/build.gradle.kts | 1 - .../v7_1/AersopikeSingletons.java | 2 +- .../v7_1/AerospikeClientAsyncCommandTest.java | 5 ++++- .../v7_1/AerospikeClientSyncCommandTest.java | 22 ++++++++----------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index 5921a95c8d98..4758c7821153 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -7,7 +7,6 @@ muzzle { group.set("com.aerospike") module.set("aerospike-client") versions.set("[7.1.0,)") - assertInverse.set(true) } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java index d7c66a7e8cbd..70f48f04b6d2 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java @@ -15,7 +15,7 @@ import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; public final class AersopikeSingletons { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.0"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.1"; private static final Instrumenter INSTRUMENTER; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java index 2df1de9e8c0a..288cd4dbc7cf 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class AerospikeClientAsyncCommandTest { @@ -35,7 +36,9 @@ class AerospikeClientAsyncCommandTest { static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); static GenericContainer aerospikeServer = - new GenericContainer<>("aerospike/aerospike-server:6.2.0.0").withExposedPorts(3000); + new GenericContainer<>("aerospike/aerospike-server:6.2.0.0") + .withExposedPorts(3000) + .waitingFor(Wait.forLogMessage(".*applied cluster size 1.*", 1)); static int port; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java index 6c2349f5b647..8eb58f08039e 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class AerospikeClientSyncCommandTest { @@ -33,7 +34,9 @@ class AerospikeClientSyncCommandTest { static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); static GenericContainer aerospikeServer = - new GenericContainer<>("aerospike/aerospike-server:6.2.0.0").withExposedPorts(3000); + new GenericContainer<>("aerospike/aerospike-server:6.2.0.0") + .withExposedPorts(3000) + .waitingFor(Wait.forLogMessage(".*applied cluster size 1.*", 1)); static int port; static AerospikeClient aerospikeClient; @@ -56,9 +59,12 @@ void setup() { } @Test - void putCommand() { + void putAndGetCommand() { Key aerospikeKey = new Key("test", "test-set", "data1"); aerospikeClient.put(null, aerospikeKey, new Bin("bin1", "value1")); + List bins = singletonList("bin1"); + Record aerospikeRecord = aerospikeClient.get(null, aerospikeKey, bins.toArray(new String[0])); + assertThat(aerospikeRecord.getString("bin1")).isEqualTo("value1"); testing.waitAndAssertTraces( trace -> @@ -79,17 +85,7 @@ void putCommand() { equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 95), satisfies( SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1"))))); - } - - @Test - void getCommand() { - Key aerospikeKey = new Key("test", "test-set", "data1"); - List bins = singletonList("bin1"); - Record aerospikeRecord = aerospikeClient.get(null, aerospikeKey, bins.toArray(new String[0])); - assertThat(aerospikeRecord.getString("bin1")).isEqualTo("value1"); - - testing.waitAndAssertTraces( + val -> val.isIn("localhost", "127.0.0.1")))), trace -> trace.hasSpansSatisfyingExactly( span -> From 226b9e1e36d1b7e20cc3b301485c6c2d23ed4086 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 10 Nov 2023 13:42:39 +0530 Subject: [PATCH 04/21] checkstyle complaint package name update --- .../AerospikeClientAttributeExtractor.java | 2 +- .../AerospikeClientInstrumentationModule.java | 2 +- .../v7_1/AerospikeRequest.java | 2 +- .../v7_1/AerospikeRequestContext.java | 2 +- .../v7_1/AersopikeSingletons.java | 2 +- .../v7_1/AsyncCommandInstrumentation.java | 4 +- .../v7_1/AsyncHandlerInstrumentation.java | 15 +++----- .../AsyncScanAllCommandInstrumentation.java | 19 ++++------ .../v7_1/DbAttributesGetter.java | 2 +- .../v7_1/NetworkAttributesGetter.java | 2 +- .../v7_1/SocketInstrumentation.java | 6 +-- .../v7_1/Status.java | 2 +- .../v7_1/SyncCommandInstrumentation.java | 38 +++++++++---------- .../v7_1/TransferSizeIntrumentation.java | 2 +- .../v7_1/AerospikeClientAsyncCommandTest.java | 2 +- .../v7_1/AerospikeClientSyncCommandTest.java | 2 +- 16 files changed, 47 insertions(+), 57 deletions(-) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AerospikeClientAttributeExtractor.java (96%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AerospikeClientInstrumentationModule.java (94%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AerospikeRequest.java (94%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AerospikeRequestContext.java (94%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AersopikeSingletons.java (96%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AsyncCommandInstrumentation.java (96%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AsyncHandlerInstrumentation.java (83%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AsyncScanAllCommandInstrumentation.java (87%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/DbAttributesGetter.java (93%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/NetworkAttributesGetter.java (91%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/SocketInstrumentation.java (95%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/Status.java (67%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/SyncCommandInstrumentation.java (84%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/TransferSizeIntrumentation.java (95%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AerospikeClientAsyncCommandTest.java (98%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/{aerospike_client => aerospike}/v7_1/AerospikeClientSyncCommandTest.java (98%) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java similarity index 96% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java index 1af35170fe25..32dcf96a935d 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAttributeExtractor.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import com.aerospike.client.AerospikeException; import com.aerospike.client.ResultCode; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java similarity index 94% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java index ccd487eef554..1edccfc3b8ea 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static java.util.Arrays.asList; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequest.java similarity index 94% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequest.java index 1436e7f928d7..f64cd0de7d60 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import com.aerospike.client.Key; import com.aerospike.client.cluster.Node; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java similarity index 94% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java index 1631855dec2b..8e90ae8d5ac0 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeRequestContext.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java similarity index 96% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java index 70f48f04b6d2..d5ef71cec885 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java similarity index 96% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java index eb6bdb5351cc..690f335ab481 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AersopikeSingletons.instrumenter; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isConstructor; import static net.bytebuddy.matcher.ElementMatchers.isPublic; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java similarity index 83% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java index e4a3262936be..13e6ea03d8a0 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncHandlerInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java @@ -3,11 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.SUCCESS; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isProtected; import static net.bytebuddy.matcher.ElementMatchers.named; @@ -56,11 +53,11 @@ public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Comma AerospikeRequest request = requestContext.getRequest(); Context context = requestContext.getContext(); if (throwable == null) { - request.setStatus(SUCCESS); + request.setStatus(Status.SUCCESS); } else { - request.setStatus(FAILURE); + request.setStatus(Status.FAILURE); } - requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); Scope scope = context.makeCurrent(); if (null != scope) { scope.close(); @@ -81,8 +78,8 @@ public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Comma if (requestContext != null) { AerospikeRequest request = requestContext.getRequest(); Context context = requestContext.getContext(); - request.setStatus(FAILURE); - requestContext.endSpan(instrumenter(), context, request, throwable); + request.setStatus(Status.FAILURE); + requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); Scope scope = context.makeCurrent(); if (null != scope) { scope.close(); diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java similarity index 87% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java index d728c9ed83d2..de027b312cb1 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AsyncScanAllCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java @@ -3,12 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.SUCCESS; import static net.bytebuddy.matcher.ElementMatchers.isConstructor; import static net.bytebuddy.matcher.ElementMatchers.isProtected; import static net.bytebuddy.matcher.ElementMatchers.isPublic; @@ -69,10 +66,10 @@ public static void onExit( asyncScanPartitionExecutor.getClass().getSimpleName().toUpperCase(Locale.ROOT), namespace, setName); - if (!instrumenter().shouldStart(parentContext, request)) { + if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { return; } - context = instrumenter().start(parentContext, request); + context = AersopikeSingletons.instrumenter().start(parentContext, request); AerospikeRequestContext aerospikeRequestContext = AerospikeRequestContext.attach(request, context); scope = context.makeCurrent(); @@ -99,11 +96,11 @@ public static void onExit( AerospikeRequest request = requestContext.getRequest(); Context context = requestContext.getContext(); if (throwable == null) { - request.setStatus(SUCCESS); + request.setStatus(Status.SUCCESS); } else { - request.setStatus(FAILURE); + request.setStatus(Status.FAILURE); } - requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); Scope scope = context.makeCurrent(); if (null != scope) { scope.close(); @@ -126,8 +123,8 @@ public static void onExit( if (requestContext != null) { AerospikeRequest request = requestContext.getRequest(); Context context = requestContext.getContext(); - request.setStatus(FAILURE); - requestContext.endSpan(instrumenter(), context, request, throwable); + request.setStatus(Status.FAILURE); + requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); Scope scope = context.makeCurrent(); if (null != scope) { scope.close(); diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/DbAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java similarity index 93% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/DbAttributesGetter.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java index 08664a5a0577..da97a0fe37d7 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/DbAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesGetter; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/NetworkAttributesGetter.java similarity index 91% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/NetworkAttributesGetter.java index 5503e9e23ab1..18fc007a9bff 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/NetworkAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/NetworkAttributesGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import com.aerospike.client.cluster.Node; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java similarity index 95% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java index c8ce10c5ab52..d50ffc9aa4da 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SocketInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.Status.FAILURE; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isProtected; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/Status.java similarity index 67% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/Status.java index df1451836a47..32ad873bbac0 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/Status.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/Status.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; public enum Status { SUCCESS, diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java similarity index 84% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java index d075ec76462e..44c74f234bb6 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/SyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java @@ -3,13 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.FAILURE; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.RECORD_NOT_FOUND; -import static io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1.Status.SUCCESS; import static net.bytebuddy.matcher.ElementMatchers.isFinal; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isPublic; @@ -89,10 +85,10 @@ public static AerospikeRequestContext onEnter( return null; } request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key); - if (!instrumenter().shouldStart(parentContext, request)) { + if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { return null; } - context = instrumenter().start(parentContext, request); + context = AersopikeSingletons.instrumenter().start(parentContext, request); scope = context.makeCurrent(); return AerospikeRequestContext.attach(request, context); } @@ -106,11 +102,11 @@ public static void stopSpan( @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { if (throwable != null) { - request.setStatus(FAILURE); + request.setStatus(Status.FAILURE); } else if (record == null) { - request.setStatus(RECORD_NOT_FOUND); + request.setStatus(Status.RECORD_NOT_FOUND); } else { - request.setStatus(SUCCESS); + request.setStatus(Status.SUCCESS); } if (scope == null) { return; @@ -118,7 +114,7 @@ public static void stopSpan( scope.close(); if (requestContext != null) { - requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); requestContext.detachAndEnd(); } } @@ -145,10 +141,10 @@ public static AerospikeRequestContext onEnter( return null; } request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key); - if (!instrumenter().shouldStart(parentContext, request)) { + if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { return null; } - context = instrumenter().start(parentContext, request); + context = AersopikeSingletons.instrumenter().start(parentContext, request); scope = context.makeCurrent(); return AerospikeRequestContext.attach(request, context); } @@ -161,9 +157,9 @@ public static AerospikeRequestContext stopSpan( @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { if (throwable != null) { - request.setStatus(FAILURE); + request.setStatus(Status.FAILURE); } else { - request.setStatus(SUCCESS); + request.setStatus(Status.SUCCESS); } if (scope == null) { return requestContext; @@ -171,7 +167,7 @@ public static AerospikeRequestContext stopSpan( scope.close(); if (requestContext != null) { - requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); requestContext.detachAndEnd(); } return requestContext; @@ -192,10 +188,10 @@ public static AerospikeRequestContext onEnter( Context parentContext = currentContext(); request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), namespace, setName); - if (!instrumenter().shouldStart(parentContext, request)) { + if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { return null; } - context = instrumenter().start(parentContext, request); + context = AersopikeSingletons.instrumenter().start(parentContext, request); scope = context.makeCurrent(); return AerospikeRequestContext.attach(request, context); } @@ -208,9 +204,9 @@ public static AerospikeRequestContext stopSpan( @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { if (throwable != null) { - request.setStatus(FAILURE); + request.setStatus(Status.FAILURE); } else { - request.setStatus(SUCCESS); + request.setStatus(Status.SUCCESS); } if (scope == null) { return requestContext; @@ -218,7 +214,7 @@ public static AerospikeRequestContext stopSpan( scope.close(); if (requestContext != null) { - requestContext.endSpan(instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); requestContext.detachAndEnd(); } return requestContext; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/TransferSizeIntrumentation.java similarity index 95% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/TransferSizeIntrumentation.java index bd0a4f6fd43c..ce5b8e376e53 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/TransferSizeIntrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/TransferSizeIntrumentation.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isMethod; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java similarity index 98% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java index 288cd4dbc7cf..cdf9231b6e12 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientAsyncCommandTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java similarity index 98% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java index 8eb58f08039e..11cbabbc4cec 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike_client/v7_1/AerospikeClientSyncCommandTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike_client.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; From ec950dcaa75b4dad7c224b1f9f9444f54fadea85 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 10 Nov 2023 18:43:00 +0530 Subject: [PATCH 05/21] changes tests to include server close --- .../aerospike/v7_1/AerospikeClientAsyncCommandTest.java | 3 ++- .../aerospike/v7_1/AerospikeClientSyncCommandTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java index cdf9231b6e12..30a91aae92ba 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java @@ -38,7 +38,7 @@ class AerospikeClientAsyncCommandTest { static GenericContainer aerospikeServer = new GenericContainer<>("aerospike/aerospike-server:6.2.0.0") .withExposedPorts(3000) - .waitingFor(Wait.forLogMessage(".*applied cluster size 1.*", 1)); + .waitingFor(Wait.forLogMessage(".*replication factor is 1.*", 1)); static int port; @@ -62,6 +62,7 @@ static void setupSpec() { @AfterAll static void cleanupSpec() { aerospikeClient.close(); + aerospikeServer.stop(); } @BeforeEach diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java index 11cbabbc4cec..85e8e83dca9e 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java @@ -36,7 +36,7 @@ class AerospikeClientSyncCommandTest { static GenericContainer aerospikeServer = new GenericContainer<>("aerospike/aerospike-server:6.2.0.0") .withExposedPorts(3000) - .waitingFor(Wait.forLogMessage(".*applied cluster size 1.*", 1)); + .waitingFor(Wait.forLogMessage(".*replication factor is 1.*", 1)); static int port; static AerospikeClient aerospikeClient; @@ -51,6 +51,7 @@ static void setupSpec() { @AfterAll static void cleanupSpec() { aerospikeClient.close(); + aerospikeServer.stop(); } @BeforeEach From 14f1109623de0184aa39d058cfdc8db6c55ec677 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 10 Nov 2023 22:30:30 +0530 Subject: [PATCH 06/21] refactors tests --- .../AerospikeClientInstrumentationModule.java | 1 - .../v7_1/SyncCommandInstrumentation.java | 9 ++ .../v7_1/TransferSizeIntrumentation.java | 44 ------- .../v7_1/AerospikeClientSyncCommandTest.java | 110 ------------------ ...mandTest.java => AerospikeClientTest.java} | 41 +++++-- 5 files changed, 41 insertions(+), 164 deletions(-) delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/TransferSizeIntrumentation.java delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/{AerospikeClientAsyncCommandTest.java => AerospikeClientTest.java} (73%) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java index 1edccfc3b8ea..bb35a17114e9 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java @@ -31,7 +31,6 @@ public List typeInstrumentations() { return asList( new SyncCommandInstrumentation(), new SocketInstrumentation(), - new TransferSizeIntrumentation(), new AsyncCommandInstrumentation(), new AsyncHandlerInstrumentation(), new AsyncScanAllCommandInstrumentation()); diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java index 44c74f234bb6..3e2009cbe009 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java @@ -108,6 +108,15 @@ public static void stopSpan( } else { request.setStatus(Status.SUCCESS); } + if (record == null || record.bins.isEmpty()) { + request.setSize(0); + } else { + int size = 0; + for (Object value : record.bins.values()) { + size += ((String) value).length(); + } + request.setSize(size); + } if (scope == null) { return; } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/TransferSizeIntrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/TransferSizeIntrumentation.java deleted file mode 100644 index ce5b8e376e53..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/TransferSizeIntrumentation.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; - -import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; -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.takesNoArguments; - -import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; -import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import net.bytebuddy.asm.Advice; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.matcher.ElementMatcher; - -public class TransferSizeIntrumentation implements TypeInstrumentation { - @Override - public ElementMatcher typeMatcher() { - return hasSuperClass(named("com.aerospike.client.command.Command")); - } - - @Override - public void transform(TypeTransformer transformer) { - transformer.applyAdviceToMethod( - isMethod().and(isPublic()).and(named("execute")).and(takesNoArguments()), - this.getClass().getName() + "$SizeAdvice"); - } - - @SuppressWarnings("unused") - public static class SizeAdvice { - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan(@Advice.FieldValue("dataOffset") int dataOffset) { - AerospikeRequestContext context = AerospikeRequestContext.current(); - if (context != null) { - AerospikeRequest request = context.getRequest(); - request.setSize(dataOffset); - } - } - } -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java deleted file mode 100644 index 85e8e83dca9e..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientSyncCommandTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; - -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; - -import com.aerospike.client.AerospikeClient; -import com.aerospike.client.Bin; -import com.aerospike.client.Key; -import com.aerospike.client.Record; -import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; -import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; -import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.List; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.containers.wait.strategy.Wait; - -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 -class AerospikeClientSyncCommandTest { - @RegisterExtension - static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); - - static GenericContainer aerospikeServer = - new GenericContainer<>("aerospike/aerospike-server:6.2.0.0") - .withExposedPorts(3000) - .waitingFor(Wait.forLogMessage(".*replication factor is 1.*", 1)); - static int port; - - static AerospikeClient aerospikeClient; - - @BeforeAll - static void setupSpec() { - aerospikeServer.start(); - port = aerospikeServer.getMappedPort(3000); - aerospikeClient = new AerospikeClient("localhost", port); - } - - @AfterAll - static void cleanupSpec() { - aerospikeClient.close(); - aerospikeServer.stop(); - } - - @BeforeEach - void setup() { - testing.clearData(); - } - - @Test - void putAndGetCommand() { - Key aerospikeKey = new Key("test", "test-set", "data1"); - aerospikeClient.put(null, aerospikeKey, new Bin("bin1", "value1")); - List bins = singletonList("bin1"); - Record aerospikeRecord = aerospikeClient.get(null, aerospikeKey, bins.toArray(new String[0])); - assertThat(aerospikeRecord.getString("bin1")).isEqualTo("value1"); - - testing.waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("PUT") - .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "PUT"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 95), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")))), - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("GET") - .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 40), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1"))))); - } -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java similarity index 73% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java index 30a91aae92ba..760d0321d07a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAsyncCommandTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java @@ -8,10 +8,12 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; import com.aerospike.client.AerospikeClient; import com.aerospike.client.Bin; import com.aerospike.client.Key; +import com.aerospike.client.Record; import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.EventPolicy; import com.aerospike.client.async.NioEventLoops; @@ -31,7 +33,7 @@ import org.testcontainers.containers.wait.strategy.Wait; @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 -class AerospikeClientAsyncCommandTest { +class AerospikeClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @@ -71,7 +73,7 @@ void setup() { } @Test - void putCommand() { + void asyncCommand() { Key aerospikeKey = new Key("test", "test-set", "data1"); aerospikeClient.put(null, null, null, aerospikeKey, new Bin("bin1", "value1")); @@ -97,27 +99,48 @@ void putCommand() { } @Test - void getCommand() { - Key aerospikeKey = new Key("test", "test-set", "data1"); - List bins = singletonList("bin1"); - aerospikeClient.get(null, null, null, aerospikeKey, bins.toArray(new String[0])); + void syncCommand() { + Key aerospikeKey = new Key("test", "test-set", "data2"); + aerospikeClient.put(null, aerospikeKey, new Bin("bin2", "value2")); + List bins = singletonList("bin2"); + Record aerospikeRecord = aerospikeClient.get(null, aerospikeKey, bins.toArray(new String[0])); + assertThat(aerospikeRecord.getString("bin2")).isEqualTo("value2"); testing.waitAndAssertTraces( trace -> trace.hasSpansSatisfyingExactly( span -> - span.hasName("ASYNCREAD") + span.hasName("PUT") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "ASYNCREAD"), + equalTo(SemanticAttributes.DB_OPERATION, "PUT"), equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data2"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), + satisfies( + SemanticAttributes.NET_SOCK_PEER_NAME, + val -> val.isIn("localhost", "127.0.0.1")))), + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("GET") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), + equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data2"), equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), + equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 6), satisfies( SemanticAttributes.NET_SOCK_PEER_NAME, val -> val.isIn("localhost", "127.0.0.1"))))); From 4133b58fdf719c37d373dfd27bd41e1b5c71359e Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 16 Nov 2023 02:21:03 +0530 Subject: [PATCH 07/21] removes unuseful scopes, local variables and refactors metrics --- .../javaagent/build.gradle.kts | 3 +- .../AerospikeClientAttributeExtractor.java | 2 +- .../aerospike/v7_1/AersopikeSingletons.java | 2 +- .../v7_1/AsyncCommandInstrumentation.java | 28 ++++++++----------- .../v7_1/AsyncHandlerInstrumentation.java | 15 ++++------ .../AsyncScanAllCommandInstrumentation.java | 20 ++----------- .../aerospike/v7_1/DbAttributesGetter.java | 3 +- .../aerospike/v7_1/AerospikeClientTest.java | 2 +- .../library/build.gradle.kts | 11 ++++++++ .../v7_1/AerospikeMessageSizeUtil.java | 6 ++-- .../aerospike/v7_1}/AerospikeMetrics.java | 4 +-- .../v7_1}/AerospikeMetricsAdvice.java | 2 +- .../v7_1}/AerospikeSemanticAttributes.java | 2 +- settings.gradle.kts | 1 + 14 files changed, 45 insertions(+), 56 deletions(-) create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts rename instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java => instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMessageSizeUtil.java (83%) rename {instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db => instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1}/AerospikeMetrics.java (96%) rename {instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db => instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1}/AerospikeMetricsAdvice.java (99%) rename {instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db => instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1}/AerospikeSemanticAttributes.java (94%) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index 4758c7821153..a1a95b162c1e 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -11,11 +11,12 @@ muzzle { } dependencies { + implementation(project(":instrumentation:aerospike-client:aerospike-client-7.1:library")) library("com.aerospike:aerospike-client:7.1.0") compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") - testInstrumentation(project(":instrumentation:aerospike-client:aerospike-client-7.1:javaagent")) + testImplementation(project(":instrumentation:aerospike-client:aerospike-client-7.1:library")) } tasks { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java index 32dcf96a935d..a907a917d43f 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java @@ -9,8 +9,8 @@ import com.aerospike.client.ResultCode; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; import javax.annotation.Nullable; public class AerospikeClientAttributeExtractor diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java index d5ef71cec885..ad2ce4020f1a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java @@ -6,9 +6,9 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeMetrics; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java index 690f335ab481..c00962b82e5c 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java @@ -6,17 +6,16 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AersopikeSingletons.instrumenter; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isConstructor; import static net.bytebuddy.matcher.ElementMatchers.isPublic; import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.not; import com.aerospike.client.Key; import com.aerospike.client.command.Command; import io.opentelemetry.context.Context; -import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.util.VirtualField; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -26,11 +25,15 @@ import net.bytebuddy.matcher.ElementMatcher; public class AsyncCommandInstrumentation implements TypeInstrumentation { + + @Override + public ElementMatcher classLoaderOptimization() { + return hasClassesNamed("com.aerospike.client.async.AsyncCommand"); + } + @Override public ElementMatcher typeMatcher() { - return hasSuperClass( - named("com.aerospike.client.async.AsyncCommand") - .and(not(named("com.aerospike.client.command.Command")))); + return hasSuperClass(named("com.aerospike.client.async.AsyncCommand")); } @Override @@ -42,12 +45,7 @@ public void transform(TypeTransformer transformer) { @SuppressWarnings("unused") public static class ConstructorAdvice { @Advice.OnMethodExit(suppress = Throwable.class) - public static void onExit( - @Advice.This Command command, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope, - @Advice.AllArguments Object[] objects) { + public static void onExit(@Advice.This Command command, @Advice.AllArguments Object[] objects) { Key key = null; for (Object object : objects) { if (object instanceof Key) { @@ -65,20 +63,16 @@ public static void onExit( return; } Context parentContext = currentContext(); - request = + AerospikeRequest request = AerospikeRequest.create(command.getClass().getSimpleName().toUpperCase(Locale.ROOT), key); if (!instrumenter().shouldStart(parentContext, request)) { return; } - context = instrumenter().start(parentContext, request); + Context context = instrumenter().start(parentContext, request); AerospikeRequestContext aerospikeRequestContext = AerospikeRequestContext.attach(request, context); - scope = context.makeCurrent(); virtualField.set(command, aerospikeRequestContext); - if (scope != null) { - scope.close(); - } } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java index 13e6ea03d8a0..f9c8717efd7b 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isProtected; import static net.bytebuddy.matcher.ElementMatchers.named; @@ -13,7 +14,6 @@ import com.aerospike.client.command.Command; import io.opentelemetry.context.Context; -import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.util.VirtualField; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -23,6 +23,11 @@ public class AsyncHandlerInstrumentation implements TypeInstrumentation { + @Override + public ElementMatcher classLoaderOptimization() { + return hasClassesNamed("com.aerospike.client.command.Command"); + } + @Override public ElementMatcher typeMatcher() { return hasSuperClass(named("com.aerospike.client.command.Command")); @@ -58,10 +63,6 @@ public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Comma request.setStatus(Status.FAILURE); } requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); - Scope scope = context.makeCurrent(); - if (null != scope) { - scope.close(); - } } } } @@ -80,10 +81,6 @@ public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Comma Context context = requestContext.getContext(); request.setStatus(Status.FAILURE); requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); - Scope scope = context.makeCurrent(); - if (null != scope) { - scope.close(); - } } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java index de027b312cb1..d705a74c1343 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java @@ -15,7 +15,6 @@ import com.aerospike.client.async.AsyncScanPartitionExecutor; import io.opentelemetry.context.Context; -import io.opentelemetry.context.Scope; import io.opentelemetry.instrumentation.api.util.VirtualField; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -49,9 +48,6 @@ public static class ConstructorAdvice { @Advice.OnMethodExit(suppress = Throwable.class) public static void onExit( @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope, @Advice.Argument(4) String namespace, @Advice.Argument(5) String setName) { VirtualField virtualField = @@ -61,7 +57,7 @@ public static void onExit( return; } Context parentContext = currentContext(); - request = + AerospikeRequest request = AerospikeRequest.create( asyncScanPartitionExecutor.getClass().getSimpleName().toUpperCase(Locale.ROOT), namespace, @@ -69,15 +65,11 @@ public static void onExit( if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { return; } - context = AersopikeSingletons.instrumenter().start(parentContext, request); + Context context = AersopikeSingletons.instrumenter().start(parentContext, request); AerospikeRequestContext aerospikeRequestContext = AerospikeRequestContext.attach(request, context); - scope = context.makeCurrent(); virtualField.set(asyncScanPartitionExecutor, aerospikeRequestContext); - if (scope != null) { - scope.close(); - } } } @@ -101,10 +93,6 @@ public static void onExit( request.setStatus(Status.FAILURE); } requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); - Scope scope = context.makeCurrent(); - if (null != scope) { - scope.close(); - } } } } @@ -125,10 +113,6 @@ public static void onExit( Context context = requestContext.getContext(); request.setStatus(Status.FAILURE); requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); - Scope scope = context.makeCurrent(); - if (null != scope) { - scope.close(); - } } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java index da97a0fe37d7..a7c0426e94f1 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java @@ -5,7 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; -import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; + +import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesGetter; import javax.annotation.Nullable; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java index 760d0321d07a..33e94726183c 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java @@ -19,7 +19,7 @@ import com.aerospike.client.async.NioEventLoops; import com.aerospike.client.policy.ClientPolicy; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.api.instrumenter.db.AerospikeSemanticAttributes; +import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.semconv.SemanticAttributes; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts new file mode 100644 index 000000000000..1d6fd1e718be --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("otel.library-instrumentation") + id("otel.animalsniffer-conventions") +} + +dependencies { + implementation("io.opentelemetry:opentelemetry-extension-incubator") + + compileOnly("com.google.auto.value:auto-value-annotations") + annotationProcessor("com.google.auto.value:auto-value") +} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMessageSizeUtil.java similarity index 83% rename from instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java rename to instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMessageSizeUtil.java index cd27a32fda45..d0b1a008597d 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/DbMessageSizeUtil.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMessageSizeUtil.java @@ -3,13 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter.db; +package io.opentelemetry.instrumentation.aerospike.v7_1; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import javax.annotation.Nullable; -final class DbMessageSizeUtil { +final class AerospikeMessageSizeUtil { @Nullable static Long getMessageSize(Attributes... attributesList) { @@ -27,5 +27,5 @@ private static T getAttribute(AttributeKey key, Attributes... attributesL return null; } - private DbMessageSizeUtil() {} + private AerospikeMessageSizeUtil() {} } diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetrics.java similarity index 96% rename from instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java rename to instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetrics.java index a8e0e5c7991f..72ff15107625 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetrics.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetrics.java @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter.db; +package io.opentelemetry.instrumentation.aerospike.v7_1; -import static io.opentelemetry.instrumentation.api.instrumenter.db.DbMessageSizeUtil.getMessageSize; +import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeMessageSizeUtil.getMessageSize; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsAdvice.java similarity index 99% rename from instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java rename to instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsAdvice.java index 24f604332c31..c28d25feaea7 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeMetricsAdvice.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsAdvice.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter.db; +package io.opentelemetry.instrumentation.aerospike.v7_1; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java similarity index 94% rename from instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java rename to instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java index 66eb05161309..9aeb77bd1d78 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/db/AerospikeSemanticAttributes.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.api.instrumenter.db; +package io.opentelemetry.instrumentation.aerospike.v7_1; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; diff --git a/settings.gradle.kts b/settings.gradle.kts index c894d1de9eda..78dc3dd07308 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -139,6 +139,7 @@ include(":smoke-tests:images:spring-boot") include(":smoke-tests-otel-starter") include(":instrumentation:aerospike-client:aerospike-client-7.1:javaagent") +include(":instrumentation:aerospike-client:aerospike-client-7.1:library") include(":instrumentation:akka:akka-actor-2.3:javaagent") include(":instrumentation:akka:akka-actor-fork-join-2.5:javaagent") include(":instrumentation:akka:akka-http-10.0:javaagent") From b4af69a8f59c53fa8a2672f9343a5919599780f9 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sat, 18 Nov 2023 12:51:58 +0530 Subject: [PATCH 08/21] adds aerospike metrics test and adds check for experimental-span-attributes and formatting change --- :test | 22 ++ .../javaagent/build.gradle.kts | 1 + .../aerospike/v7_1/AersopikeSingletons.java | 14 +- .../aerospike/v7_1/DbAttributesGetter.java | 1 - .../aerospike/v7_1/AerospikeMetricsTest.java | 239 ++++++++++++++++++ 5 files changed, 272 insertions(+), 5 deletions(-) create mode 100644 :test create mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java diff --git a/:test b/:test new file mode 100644 index 000000000000..2fc8c2e8f8a6 --- /dev/null +++ b/:test @@ -0,0 +1,22 @@ +> Task :conventions:extractPrecompiledScriptPluginPlugins UP-TO-DATE +> Task :conventions:generateScriptPluginAdapters UP-TO-DATE +> Task :conventions:pluginDescriptors UP-TO-DATE +> Task :conventions:processResources UP-TO-DATE +> Task :gradle-plugins:generateExternalPluginSpecBuilders UP-TO-DATE +> Task :gradle-plugins:extractPrecompiledScriptPluginPlugins UP-TO-DATE +> Task :gradle-plugins:compilePluginsBlocks UP-TO-DATE +> Task :gradle-plugins:generatePrecompiledScriptPluginAccessors UP-TO-DATE +> Task :gradle-plugins:generateScriptPluginAdapters UP-TO-DATE +> Task :gradle-plugins:compileKotlin UP-TO-DATE +> Task :gradle-plugins:compileJava NO-SOURCE +> Task :gradle-plugins:pluginDescriptors UP-TO-DATE +> Task :gradle-plugins:processResources UP-TO-DATE +> Task :gradle-plugins:classes UP-TO-DATE +> Task :gradle-plugins:jar UP-TO-DATE +> Task :conventions:generateExternalPluginSpecBuilders UP-TO-DATE +> Task :conventions:compilePluginsBlocks UP-TO-DATE +> Task :conventions:generatePrecompiledScriptPluginAccessors UP-TO-DATE +> Task :conventions:compileKotlin UP-TO-DATE +> Task :conventions:compileJava NO-SOURCE +> Task :conventions:classes UP-TO-DATE +> Task :conventions:jar UP-TO-DATE diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index a1a95b162c1e..043e6caf7f07 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { tasks { test { jvmArgs("-Djava.net.preferIPv4Stack=true") + jvmArgs("-Dotel.instrumentation.aerospike.experimental-span-attributes=true") usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java index ad2ce4020f1a..a77ffe98256a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java @@ -8,11 +8,13 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeMetrics; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; public final class AersopikeSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.1"; @@ -23,17 +25,21 @@ public final class AersopikeSingletons { DbAttributesGetter dbAttributesGetter = new DbAttributesGetter(); NetworkAttributesGetter netAttributesGetter = new NetworkAttributesGetter(); - INSTRUMENTER = + InstrumenterBuilder builder = Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, DbClientSpanNameExtractor.create(dbAttributesGetter)) - .addAttributesExtractor(new AerospikeClientAttributeExtractor()) .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) - .addOperationMetrics(AerospikeMetrics.get()) - .buildInstrumenter(SpanKindExtractor.alwaysClient()); + .addOperationMetrics(AerospikeMetrics.get()); + if (InstrumentationConfig.get() + .getBoolean("otel.instrumentation.aerospike.experimental-span-attributes", false)) { + builder.addAttributesExtractor(new AerospikeClientAttributeExtractor()); + } + + INSTRUMENTER = builder.buildInstrumenter(SpanKindExtractor.alwaysClient()); } public static Instrumenter instrumenter() { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java index a7c0426e94f1..e7d4f44c8ee4 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java @@ -5,7 +5,6 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; - import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesGetter; import javax.annotation.Nullable; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java new file mode 100644 index 000000000000..3ceca76222f1 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java @@ -0,0 +1,239 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.aerospike.v7_1; + +import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE; +import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE; +import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_SET_NAME; +import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_STATUS; +import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_USER_KEY; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; + +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.TraceFlags; +import io.opentelemetry.api.trace.TraceState; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; +import io.opentelemetry.semconv.SemanticAttributes; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.Test; + +class AerospikeMetricsTest { + + @Test + @SuppressWarnings("deprecation") + // until old http semconv are dropped in 2.0 + void collectsMetrics() { + InMemoryMetricReader metricReader = InMemoryMetricReader.create(); + SdkMeterProvider meterProvider = + SdkMeterProvider.builder().registerMetricReader(metricReader).build(); + + OperationListener listener = AerospikeMetrics.get().create(meterProvider.get("test")); + + Attributes startAttributes = + Attributes.builder() + .put("aerospike.namespace", "test") + .put("aerospike.set.name", "test-set") + .put("aerospike.user.key", "data2") + .put("db.operation", "GET") + .put("db.system", "aerospike") + .build(); + + Attributes endAttributes = + Attributes.builder() + .put("aerospike.error.code", 0) + .put("aerospike.status", "SUCCESS") + .put("net.sock.peer.port", 62573) + .put("net.sock.peer.name", "localhost") + .put("net.sock.peer.addr", "127.0.0.1") + .put("aerospike.transfer.size", 6) + .build(); + + Context parent = + Context.root() + .with( + Span.wrap( + SpanContext.create( + "ff01020304050600ff0a0b0c0d0e0f00", + "090a0b0c0d0e0f00", + TraceFlags.getSampled(), + TraceState.getDefault()))); + + Context context1 = listener.onStart(parent, startAttributes, nanos(100)); + + Context context2 = listener.onStart(Context.root(), startAttributes, nanos(150)); + + listener.onEnd(context1, endAttributes, nanos(250)); + + assertThat(metricReader.collectAllMetrics()) + .satisfiesExactlyInAnyOrder( + metric -> + assertThat(metric) + .hasName("aerospike.requests") + .hasLongSumSatisfying( + counter -> + counter.hasPointsSatisfying( + point -> + point + .hasValue(2) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") + .hasSpanId("090a0b0c0d0e0f00")))), + metric -> + assertThat(metric) + .hasName("aerospike.response") + .hasLongSumSatisfying( + counter -> + counter.hasPointsSatisfying( + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, 62573), + equalTo( + SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo( + SemanticAttributes.NET_SOCK_PEER_NAME, "localhost")) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") + .hasSpanId("090a0b0c0d0e0f00")))), + metric -> + assertThat(metric) + .hasName("aerospike.concurrreny") + .hasLongSumSatisfying( + upDownCounter -> + upDownCounter.hasPointsSatisfying( + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") + .hasSpanId("090a0b0c0d0e0f00")))), + metric -> + assertThat(metric) + .hasName("aerospike.client.duration") + .hasUnit("ms") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point + .hasSum(150) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, 62573), + equalTo( + SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo( + SemanticAttributes.NET_SOCK_PEER_NAME, "localhost")) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") + .hasSpanId("090a0b0c0d0e0f00")))), + metric -> + assertThat(metric) + .hasName("aerospike.record.size") + .hasUnit("By") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point + .hasSum(6) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, 62573), + equalTo( + SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), + equalTo( + SemanticAttributes.NET_SOCK_PEER_NAME, "localhost")) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") + .hasSpanId("090a0b0c0d0e0f00"))))); + + listener.onEnd(context2, endAttributes, nanos(300)); + + assertThat(metricReader.collectAllMetrics()) + .satisfiesExactlyInAnyOrder( + metric -> + assertThat(metric) + .hasName("aerospike.requests") + .hasLongSumSatisfying( + counter -> counter.hasPointsSatisfying(point -> point.hasValue(2))), + metric -> + assertThat(metric) + .hasName("aerospike.response") + .hasLongSumSatisfying( + counter -> counter.hasPointsSatisfying(point -> point.hasValue(2))), + metric -> + assertThat(metric) + .hasName("aerospike.concurrreny") + .hasLongSumSatisfying( + upDownCounter -> + upDownCounter.hasPointsSatisfying(point -> point.hasValue(0))), + metric -> + assertThat(metric) + .hasName("aerospike.client.duration") + .hasUnit("ms") + .hasHistogramSatisfying( + histogram -> histogram.hasPointsSatisfying(point -> point.hasSum(300))), + metric -> + assertThat(metric) + .hasName("aerospike.record.size") + .hasUnit("By") + .hasHistogramSatisfying( + histogram -> histogram.hasPointsSatisfying(point -> point.hasSum(12)))); + } + + private static long nanos(int millis) { + return TimeUnit.MILLISECONDS.toNanos(millis); + } +} From d1818c19aec21f9a43b221f10f61f66388397f3a Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sat, 18 Nov 2023 15:41:15 +0530 Subject: [PATCH 09/21] adds muzzle assert inverse --- .../aerospike-client-7.1/javaagent/build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index 043e6caf7f07..5400edf38c8a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -6,7 +6,8 @@ muzzle { pass { group.set("com.aerospike") module.set("aerospike-client") - versions.set("[7.1.0,)") + versions.set("[4.4.9,)") + assertInverse.set(true) } } From e82bdcb48e8e35792d1d5e775773f6fbb3c1ac01 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sat, 18 Nov 2023 18:17:30 +0530 Subject: [PATCH 10/21] removes :test file --- :test | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 :test diff --git a/:test b/:test deleted file mode 100644 index 2fc8c2e8f8a6..000000000000 --- a/:test +++ /dev/null @@ -1,22 +0,0 @@ -> Task :conventions:extractPrecompiledScriptPluginPlugins UP-TO-DATE -> Task :conventions:generateScriptPluginAdapters UP-TO-DATE -> Task :conventions:pluginDescriptors UP-TO-DATE -> Task :conventions:processResources UP-TO-DATE -> Task :gradle-plugins:generateExternalPluginSpecBuilders UP-TO-DATE -> Task :gradle-plugins:extractPrecompiledScriptPluginPlugins UP-TO-DATE -> Task :gradle-plugins:compilePluginsBlocks UP-TO-DATE -> Task :gradle-plugins:generatePrecompiledScriptPluginAccessors UP-TO-DATE -> Task :gradle-plugins:generateScriptPluginAdapters UP-TO-DATE -> Task :gradle-plugins:compileKotlin UP-TO-DATE -> Task :gradle-plugins:compileJava NO-SOURCE -> Task :gradle-plugins:pluginDescriptors UP-TO-DATE -> Task :gradle-plugins:processResources UP-TO-DATE -> Task :gradle-plugins:classes UP-TO-DATE -> Task :gradle-plugins:jar UP-TO-DATE -> Task :conventions:generateExternalPluginSpecBuilders UP-TO-DATE -> Task :conventions:compilePluginsBlocks UP-TO-DATE -> Task :conventions:generatePrecompiledScriptPluginAccessors UP-TO-DATE -> Task :conventions:compileKotlin UP-TO-DATE -> Task :conventions:compileJava NO-SOURCE -> Task :conventions:classes UP-TO-DATE -> Task :conventions:jar UP-TO-DATE From 5059c8e16c56a800262ce89407da65ab9af1c18e Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 31 Dec 2023 19:24:52 +0530 Subject: [PATCH 11/21] refactors metrics into javaagent and updates metrics test and removes old semconv --- .../javaagent/build.gradle.kts | 5 +- .../AerospikeClientAttributeExtractor.java | 3 +- ....java => AerospikeDbAttributesGetter.java} | 5 +- ... => AerospikeNetworkAttributesGetter.java} | 8 +- .../v7_1/AerospikeSemanticAttributes.java | 2 +- .../aerospike/v7_1/AersopikeSingletons.java | 20 +- .../metrics}/AerospikeMessageSizeUtil.java | 3 +- .../v7_1/metrics}/AerospikeMetrics.java | 14 +- .../v7_1/metrics}/AerospikeMetricsAdvice.java | 80 +--- .../aerospike/v7_1/AerospikeClientTest.java | 397 +++++++++++++++--- .../library/build.gradle.kts | 11 - .../aerospike/v7_1/AerospikeMetricsTest.java | 239 ----------- settings.gradle.kts | 1 - 13 files changed, 388 insertions(+), 400 deletions(-) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/{DbAttributesGetter.java => AerospikeDbAttributesGetter.java} (75%) rename instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/{NetworkAttributesGetter.java => AerospikeNetworkAttributesGetter.java} (63%) rename instrumentation/aerospike-client/aerospike-client-7.1/{library/src/main/java/io/opentelemetry => javaagent/src/main/java/io/opentelemetry/javaagent}/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java (94%) rename instrumentation/aerospike-client/aerospike-client-7.1/{library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1 => javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics}/AerospikeMessageSizeUtil.java (81%) rename instrumentation/aerospike-client/aerospike-client-7.1/{library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1 => javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics}/AerospikeMetrics.java (94%) rename instrumentation/aerospike-client/aerospike-client-7.1/{library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1 => javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics}/AerospikeMetricsAdvice.java (57%) delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index 5400edf38c8a..20e36f830754 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -1,5 +1,7 @@ plugins { id("otel.javaagent-instrumentation") + id("otel.library-instrumentation") + id("otel.animalsniffer-conventions") } muzzle { @@ -12,12 +14,11 @@ muzzle { } dependencies { - implementation(project(":instrumentation:aerospike-client:aerospike-client-7.1:library")) library("com.aerospike:aerospike-client:7.1.0") + implementation("io.opentelemetry:opentelemetry-extension-incubator") compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") - testImplementation(project(":instrumentation:aerospike-client:aerospike-client-7.1:library")) } tasks { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java index a907a917d43f..71cd93b1607f 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java @@ -9,11 +9,10 @@ import com.aerospike.client.ResultCode; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; import javax.annotation.Nullable; -public class AerospikeClientAttributeExtractor +final class AerospikeClientAttributeExtractor implements AttributesExtractor { @Override diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeDbAttributesGetter.java similarity index 75% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeDbAttributesGetter.java index e7d4f44c8ee4..e08388d69718 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/DbAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeDbAttributesGetter.java @@ -5,11 +5,10 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; -import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; -import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesGetter; +import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import javax.annotation.Nullable; -final class DbAttributesGetter implements DbClientAttributesGetter { +final class AerospikeDbAttributesGetter implements DbClientAttributesGetter { @Override public String getSystem(AerospikeRequest request) { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/NetworkAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeNetworkAttributesGetter.java similarity index 63% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/NetworkAttributesGetter.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeNetworkAttributesGetter.java index 18fc007a9bff..859181fb405a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/NetworkAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeNetworkAttributesGetter.java @@ -6,14 +6,12 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import com.aerospike.client.cluster.Node; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesGetter; +import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; import java.net.InetSocketAddress; import javax.annotation.Nullable; -final class NetworkAttributesGetter - implements ServerAttributesGetter, - io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesGetter< - AerospikeRequest, Void> { +final class AerospikeNetworkAttributesGetter + implements NetworkAttributesGetter { @Override @Nullable diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java similarity index 94% rename from instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java index 9aeb77bd1d78..d9b6f5d66583 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java index a77ffe98256a..879340568a76 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java @@ -6,15 +6,15 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeMetrics; +import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesExtractor; +import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.db.DbClientSpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.NetworkAttributesExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.network.ServerAttributesExtractor; +import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; +import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics.AerospikeMetrics; public final class AersopikeSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.1"; @@ -22,16 +22,16 @@ public final class AersopikeSingletons { private static final Instrumenter INSTRUMENTER; static { - DbAttributesGetter dbAttributesGetter = new DbAttributesGetter(); - NetworkAttributesGetter netAttributesGetter = new NetworkAttributesGetter(); + AerospikeDbAttributesGetter aerospikeDbAttributesGetter = new AerospikeDbAttributesGetter(); + NetworkAttributesGetter netAttributesGetter = + new AerospikeNetworkAttributesGetter(); InstrumenterBuilder builder = Instrumenter.builder( GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, - DbClientSpanNameExtractor.create(dbAttributesGetter)) - .addAttributesExtractor(DbClientAttributesExtractor.create(dbAttributesGetter)) - .addAttributesExtractor(ServerAttributesExtractor.create(netAttributesGetter)) + DbClientSpanNameExtractor.create(aerospikeDbAttributesGetter)) + .addAttributesExtractor(DbClientAttributesExtractor.create(aerospikeDbAttributesGetter)) .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) .addOperationMetrics(AerospikeMetrics.get()); if (InstrumentationConfig.get() diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMessageSizeUtil.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMessageSizeUtil.java similarity index 81% rename from instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMessageSizeUtil.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMessageSizeUtil.java index d0b1a008597d..939003497eca 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMessageSizeUtil.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMessageSizeUtil.java @@ -3,10 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; import javax.annotation.Nullable; final class AerospikeMessageSizeUtil { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetrics.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetrics.java similarity index 94% rename from instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetrics.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetrics.java index 72ff15107625..ec59462c36d3 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetrics.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetrics.java @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics; -import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeMessageSizeUtil.getMessageSize; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics.AerospikeMessageSizeUtil.getMessageSize; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -33,11 +33,13 @@ public final class AerospikeMetrics implements OperationListener { private static final Logger logger = Logger.getLogger(AerospikeMetrics.class.getName()); private final LongCounter requestCounter; + private final LongCounter responseCounter; + private final LongUpDownCounter concurrencyUpDownCounter; + private final DoubleHistogram clientLatencyHistogram; - @SuppressWarnings("unused") private final DoubleHistogram recordSizeHistogram; private AerospikeMetrics(Meter meter) { @@ -45,16 +47,19 @@ private AerospikeMetrics(Meter meter) { meter.counterBuilder("aerospike.requests").setDescription("Aerospike Calls"); AerospikeMetricsAdvice.applyRequestCounterAdvice(requestCounterBuilder); requestCounter = requestCounterBuilder.build(); + LongCounterBuilder responseCounterBuilder = meter.counterBuilder("aerospike.response").setDescription("Aerospike Responses"); AerospikeMetricsAdvice.applyResponseCounterAdvice(responseCounterBuilder); responseCounter = responseCounterBuilder.build(); + LongUpDownCounterBuilder concurrencyUpDownCounterBuilder = meter - .upDownCounterBuilder("aerospike.concurrreny") + .upDownCounterBuilder("aerospike.concurrency") .setDescription("Aerospike Concurrent Requests"); AerospikeMetricsAdvice.applyConcurrencyUpDownCounterAdvice(concurrencyUpDownCounterBuilder); concurrencyUpDownCounter = concurrencyUpDownCounterBuilder.build(); + DoubleHistogramBuilder durationBuilder = meter .histogramBuilder("aerospike.client.duration") @@ -62,6 +67,7 @@ private AerospikeMetrics(Meter meter) { .setUnit("ms"); AerospikeMetricsAdvice.applyClientDurationAdvice(durationBuilder); clientLatencyHistogram = durationBuilder.build(); + DoubleHistogramBuilder recordSizeHistogramBuilder = meter .histogramBuilder("aerospike.record.size") diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsAdvice.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetricsAdvice.java similarity index 57% rename from instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsAdvice.java rename to instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetricsAdvice.java index c28d25feaea7..415f2a424198 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/main/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsAdvice.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetricsAdvice.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; @@ -12,7 +12,8 @@ import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder; import io.opentelemetry.extension.incubator.metrics.ExtendedLongCounterBuilder; import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder; -import io.opentelemetry.instrumentation.api.internal.SemconvStability; +import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.ArrayList; import java.util.List; @@ -20,7 +21,6 @@ final class AerospikeMetricsAdvice { private AerospikeMetricsAdvice() {} - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static void applyRequestCounterAdvice(LongCounterBuilder builder) { if (!(builder instanceof ExtendedLongCounterBuilder)) { return; @@ -32,22 +32,13 @@ static void applyRequestCounterAdvice(LongCounterBuilder builder) { attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); - if (SemconvStability.emitStableHttpSemconv()) { - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(SemanticAttributes.NETWORK_TRANSPORT); - attributes.add(SemanticAttributes.SERVER_ADDRESS); - attributes.add(SemanticAttributes.SERVER_PORT); - } - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); - attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); - attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); - } + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(NetworkAttributes.NETWORK_PEER_PORT); + attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static void applyConcurrencyUpDownCounterAdvice(LongUpDownCounterBuilder builder) { if (!(builder instanceof ExtendedLongUpDownCounterBuilder)) { return; @@ -59,22 +50,13 @@ static void applyConcurrencyUpDownCounterAdvice(LongUpDownCounterBuilder builder attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); - if (SemconvStability.emitStableHttpSemconv()) { - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(SemanticAttributes.NETWORK_TRANSPORT); - attributes.add(SemanticAttributes.SERVER_ADDRESS); - attributes.add(SemanticAttributes.SERVER_PORT); - } - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); - attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); - attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); - } + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(NetworkAttributes.NETWORK_PEER_PORT); + attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); ((ExtendedLongUpDownCounterBuilder) builder).setAttributesAdvice(attributes); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static void applyResponseCounterAdvice(LongCounterBuilder builder) { if (!(builder instanceof ExtendedLongCounterBuilder)) { return; @@ -88,22 +70,13 @@ static void applyResponseCounterAdvice(LongCounterBuilder builder) { attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); - if (SemconvStability.emitStableHttpSemconv()) { - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(SemanticAttributes.NETWORK_TRANSPORT); - attributes.add(SemanticAttributes.SERVER_ADDRESS); - attributes.add(SemanticAttributes.SERVER_PORT); - } - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); - attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); - attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); - } + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(NetworkAttributes.NETWORK_PEER_PORT); + attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static void applyClientDurationAdvice(DoubleHistogramBuilder builder) { if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { return; @@ -117,22 +90,13 @@ static void applyClientDurationAdvice(DoubleHistogramBuilder builder) { attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); - if (SemconvStability.emitStableHttpSemconv()) { - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(SemanticAttributes.NETWORK_TRANSPORT); - attributes.add(SemanticAttributes.SERVER_ADDRESS); - attributes.add(SemanticAttributes.SERVER_PORT); - } - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); - attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); - attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); - } + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(NetworkAttributes.NETWORK_PEER_PORT); + attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); } - @SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 static void applyRecordSizeAdvice(DoubleHistogramBuilder builder) { if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { return; @@ -146,17 +110,9 @@ static void applyRecordSizeAdvice(DoubleHistogramBuilder builder) { attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); - if (SemconvStability.emitStableHttpSemconv()) { - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(SemanticAttributes.NETWORK_TRANSPORT); - attributes.add(SemanticAttributes.SERVER_ADDRESS); - attributes.add(SemanticAttributes.SERVER_PORT); - } - if (SemconvStability.emitOldHttpSemconv()) { - attributes.add(SemanticAttributes.NET_SOCK_PEER_ADDR); - attributes.add(SemanticAttributes.NET_SOCK_PEER_NAME); - attributes.add(SemanticAttributes.NET_SOCK_PEER_PORT); - } + attributes.add(SemanticAttributes.NETWORK_TYPE); + attributes.add(NetworkAttributes.NETWORK_PEER_PORT); + attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java index 33e94726183c..dd066bf1076f 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java @@ -5,10 +5,11 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +import static io.opentelemetry.api.common.AttributeKey.longKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies; import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; import com.aerospike.client.AerospikeClient; import com.aerospike.client.Bin; @@ -18,12 +19,14 @@ import com.aerospike.client.async.EventPolicy; import com.aerospike.client.async.NioEventLoops; import com.aerospike.client.policy.ClientPolicy; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; +import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import io.opentelemetry.semconv.SemanticAttributes; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -32,11 +35,18 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; -@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0 class AerospikeClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + public static final AttributeKey AEROSPIKE_STATUS = stringKey("aerospike.status"); + public static final AttributeKey AEROSPIKE_ERROR_CODE = longKey("aerospike.error.code"); + public static final AttributeKey AEROSPIKE_NAMESPACE = stringKey("aerospike.namespace"); + public static final AttributeKey AEROSPIKE_SET_NAME = stringKey("aerospike.set.name"); + public static final AttributeKey AEROSPIKE_USER_KEY = stringKey("aerospike.user.key"); + public static final AttributeKey AEROSPIKE_TRANSFER_SIZE = + longKey("aerospike.transfer.size"); + static GenericContainer aerospikeServer = new GenericContainer<>("aerospike/aerospike-server:6.2.0.0") .withExposedPorts(3000) @@ -77,25 +87,123 @@ void asyncCommand() { Key aerospikeKey = new Key("test", "test-set", "data1"); aerospikeClient.put(null, null, null, aerospikeKey, new Bin("bin1", "value1")); + AtomicReference instrumentationName = new AtomicReference<>(); testing.waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("ASYNCWRITE") - .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1"))))); + trace -> { + instrumentationName.set(trace.getSpan(0).getInstrumentationScopeInfo().getName()); + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("ASYNCWRITE") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data1"), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AEROSPIKE_ERROR_CODE, 0))); + }); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.requests", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasLongSumSatisfying( + counter -> + counter.hasPointsSatisfying( + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data1"), + equalTo( + SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), + equalTo( + SemanticAttributes.DB_SYSTEM, "aerospike")))))); + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.response", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasName("aerospike.response") + .hasLongSumSatisfying( + counter -> + counter.hasPointsSatisfying( + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data1"), + equalTo( + SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo( + NetworkAttributes.NETWORK_PEER_ADDRESS, + "127.0.0.1"), + equalTo( + SemanticAttributes.NETWORK_TYPE, "ipv4")))))); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.concurrency", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasLongSumSatisfying( + upDownCounter -> + upDownCounter.hasPointsSatisfying( + point -> + point + .hasValue(0) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data1"), + equalTo( + SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), + equalTo( + SemanticAttributes.DB_SYSTEM, "aerospike")))))); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.client.duration", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasUnit("ms") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point.hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data1"), + equalTo(SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo( + NetworkAttributes.NETWORK_PEER_ADDRESS, + "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")))))); } @Test @@ -106,43 +214,214 @@ void syncCommand() { Record aerospikeRecord = aerospikeClient.get(null, aerospikeKey, bins.toArray(new String[0])); assertThat(aerospikeRecord.getString("bin2")).isEqualTo("value2"); + AtomicReference instrumentationName = new AtomicReference<>(); + testing.waitAndAssertTraces( - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("PUT") - .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "PUT"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data2"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1")))), - trace -> - trace.hasSpansSatisfyingExactly( - span -> - span.hasName("GET") - .hasKind(SpanKind.CLIENT) - .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port), - equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data2"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0), - equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 6), - satisfies( - SemanticAttributes.NET_SOCK_PEER_NAME, - val -> val.isIn("localhost", "127.0.0.1"))))); + trace -> { + instrumentationName.set(trace.getSpan(0).getInstrumentationScopeInfo().getName()); + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("PUT") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "PUT"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AEROSPIKE_ERROR_CODE, 0))); + }, + trace -> { + instrumentationName.set(trace.getSpan(0).getInstrumentationScopeInfo().getName()); + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("GET") + .hasKind(SpanKind.CLIENT) + .hasAttributesSatisfyingExactly( + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), + equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_TRANSFER_SIZE, 6))); + }); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.requests", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasLongSumSatisfying( + counter -> + counter.hasPointsSatisfying( + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "PUT"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")), + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo( + SemanticAttributes.DB_SYSTEM, "aerospike")))))); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.response", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasName("aerospike.response") + .hasLongSumSatisfying( + counter -> + counter.hasPointsSatisfying( + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "PUT"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo( + NetworkAttributes.NETWORK_PEER_ADDRESS, + "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")), + point -> + point + .hasValue(1) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo( + NetworkAttributes.NETWORK_PEER_ADDRESS, + "127.0.0.1"), + equalTo( + SemanticAttributes.NETWORK_TYPE, "ipv4")))))); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.concurrency", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasLongSumSatisfying( + upDownCounter -> + upDownCounter.hasPointsSatisfying( + point -> + point + .hasValue(0) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "PUT"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")), + point -> + point + .hasValue(0) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo( + SemanticAttributes.DB_SYSTEM, "aerospike")))))); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.client.duration", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasUnit("ms") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point.hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "PUT"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo( + NetworkAttributes.NETWORK_PEER_ADDRESS, + "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")), + point -> + point.hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo( + NetworkAttributes.NETWORK_PEER_ADDRESS, + "127.0.0.1"), + equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")))))); + + testing.waitAndAssertMetrics( + instrumentationName.get(), + "aerospike.record.size", + metrics -> + metrics.anySatisfy( + metric -> + assertThat(metric) + .hasUnit("By") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point + .hasSum(6) + .hasAttributesSatisfying( + equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(AEROSPIKE_SET_NAME, "test-set"), + equalTo(AEROSPIKE_USER_KEY, "data2"), + equalTo(SemanticAttributes.DB_OPERATION, "GET"), + equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_ERROR_CODE, 0), + equalTo(AEROSPIKE_STATUS, "SUCCESS"), + equalTo( + NetworkAttributes.NETWORK_PEER_ADDRESS, + "127.0.0.1"), + equalTo( + SemanticAttributes.NETWORK_TYPE, "ipv4")))))); } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts deleted file mode 100644 index 1d6fd1e718be..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.1/library/build.gradle.kts +++ /dev/null @@ -1,11 +0,0 @@ -plugins { - id("otel.library-instrumentation") - id("otel.animalsniffer-conventions") -} - -dependencies { - implementation("io.opentelemetry:opentelemetry-extension-incubator") - - compileOnly("com.google.auto.value:auto-value-annotations") - annotationProcessor("com.google.auto.value:auto-value") -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java deleted file mode 100644 index 3ceca76222f1..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.1/library/src/test/java/io/opentelemetry/instrumentation/aerospike/v7_1/AerospikeMetricsTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.instrumentation.aerospike.v7_1; - -import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE; -import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE; -import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_SET_NAME; -import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_STATUS; -import static io.opentelemetry.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes.AEROSPIKE_USER_KEY; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; -import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; - -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.trace.Span; -import io.opentelemetry.api.trace.SpanContext; -import io.opentelemetry.api.trace.TraceFlags; -import io.opentelemetry.api.trace.TraceState; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; -import io.opentelemetry.semconv.SemanticAttributes; -import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Test; - -class AerospikeMetricsTest { - - @Test - @SuppressWarnings("deprecation") - // until old http semconv are dropped in 2.0 - void collectsMetrics() { - InMemoryMetricReader metricReader = InMemoryMetricReader.create(); - SdkMeterProvider meterProvider = - SdkMeterProvider.builder().registerMetricReader(metricReader).build(); - - OperationListener listener = AerospikeMetrics.get().create(meterProvider.get("test")); - - Attributes startAttributes = - Attributes.builder() - .put("aerospike.namespace", "test") - .put("aerospike.set.name", "test-set") - .put("aerospike.user.key", "data2") - .put("db.operation", "GET") - .put("db.system", "aerospike") - .build(); - - Attributes endAttributes = - Attributes.builder() - .put("aerospike.error.code", 0) - .put("aerospike.status", "SUCCESS") - .put("net.sock.peer.port", 62573) - .put("net.sock.peer.name", "localhost") - .put("net.sock.peer.addr", "127.0.0.1") - .put("aerospike.transfer.size", 6) - .build(); - - Context parent = - Context.root() - .with( - Span.wrap( - SpanContext.create( - "ff01020304050600ff0a0b0c0d0e0f00", - "090a0b0c0d0e0f00", - TraceFlags.getSampled(), - TraceState.getDefault()))); - - Context context1 = listener.onStart(parent, startAttributes, nanos(100)); - - Context context2 = listener.onStart(Context.root(), startAttributes, nanos(150)); - - listener.onEnd(context1, endAttributes, nanos(250)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("aerospike.requests") - .hasLongSumSatisfying( - counter -> - counter.hasPointsSatisfying( - point -> - point - .hasValue(2) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00")))), - metric -> - assertThat(metric) - .hasName("aerospike.response") - .hasLongSumSatisfying( - counter -> - counter.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, 62573), - equalTo( - SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, "localhost")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00")))), - metric -> - assertThat(metric) - .hasName("aerospike.concurrreny") - .hasLongSumSatisfying( - upDownCounter -> - upDownCounter.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00")))), - metric -> - assertThat(metric) - .hasName("aerospike.client.duration") - .hasUnit("ms") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(150) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, 62573), - equalTo( - SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, "localhost")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00")))), - metric -> - assertThat(metric) - .hasName("aerospike.record.size") - .hasUnit("By") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(6) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, 62573), - equalTo( - SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"), - equalTo( - SemanticAttributes.NET_SOCK_PEER_NAME, "localhost")) - .hasExemplarsSatisfying( - exemplar -> - exemplar - .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00"))))); - - listener.onEnd(context2, endAttributes, nanos(300)); - - assertThat(metricReader.collectAllMetrics()) - .satisfiesExactlyInAnyOrder( - metric -> - assertThat(metric) - .hasName("aerospike.requests") - .hasLongSumSatisfying( - counter -> counter.hasPointsSatisfying(point -> point.hasValue(2))), - metric -> - assertThat(metric) - .hasName("aerospike.response") - .hasLongSumSatisfying( - counter -> counter.hasPointsSatisfying(point -> point.hasValue(2))), - metric -> - assertThat(metric) - .hasName("aerospike.concurrreny") - .hasLongSumSatisfying( - upDownCounter -> - upDownCounter.hasPointsSatisfying(point -> point.hasValue(0))), - metric -> - assertThat(metric) - .hasName("aerospike.client.duration") - .hasUnit("ms") - .hasHistogramSatisfying( - histogram -> histogram.hasPointsSatisfying(point -> point.hasSum(300))), - metric -> - assertThat(metric) - .hasName("aerospike.record.size") - .hasUnit("By") - .hasHistogramSatisfying( - histogram -> histogram.hasPointsSatisfying(point -> point.hasSum(12)))); - } - - private static long nanos(int millis) { - return TimeUnit.MILLISECONDS.toNanos(millis); - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index a36f01d48416..4dc1a904924a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -139,7 +139,6 @@ include(":smoke-tests:images:spring-boot") include(":smoke-tests-otel-starter") include(":instrumentation:aerospike-client:aerospike-client-7.1:javaagent") -include(":instrumentation:aerospike-client:aerospike-client-7.1:library") include(":instrumentation:akka:akka-actor-2.3:javaagent") include(":instrumentation:akka:akka-actor-fork-join-2.5:javaagent") include(":instrumentation:akka:akka-http-10.0:javaagent") From 93da28f767e58c95ee38425e177c64f32c954870 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 31 Dec 2023 19:30:00 +0530 Subject: [PATCH 12/21] updates build.gradle --- .../aerospike-client-7.1/javaagent/build.gradle.kts | 2 -- 1 file changed, 2 deletions(-) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index 20e36f830754..a1bb22b74941 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -1,7 +1,5 @@ plugins { id("otel.javaagent-instrumentation") - id("otel.library-instrumentation") - id("otel.animalsniffer-conventions") } muzzle { From 7f84218b22e52b25eb5dd160a1cd05c4471fc0a0 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 11 Feb 2024 22:04:40 +0530 Subject: [PATCH 13/21] minor refactoring --- .../javaagent/build.gradle.kts | 3 ++- .../AerospikeClientInstrumentationModule.java | 7 +----- .../v7_1/AerospikeRequestContext.java | 7 +----- .../aerospike/v7_1/AersopikeSingletons.java | 10 ++++---- .../v7_1/AsyncHandlerInstrumentation.java | 4 ++-- .../AsyncScanAllCommandInstrumentation.java | 4 ++-- .../aerospike/v7_1/SocketInstrumentation.java | 2 +- .../v7_1/SyncCommandInstrumentation.java | 24 +++++++------------ .../aerospike/v7_1/AerospikeClientTest.java | 7 +++--- 9 files changed, 27 insertions(+), 41 deletions(-) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts index a1bb22b74941..daf1a888ed37 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts @@ -6,7 +6,7 @@ muzzle { pass { group.set("com.aerospike") module.set("aerospike-client") - versions.set("[4.4.9,)") + versions.set("[7.0.0,)") assertInverse.set(true) } } @@ -23,6 +23,7 @@ tasks { test { jvmArgs("-Djava.net.preferIPv4Stack=true") jvmArgs("-Dotel.instrumentation.aerospike.experimental-span-attributes=true") + jvmArgs("-Dotel.instrumentation.aerospike.experimental-metrics=true") usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java index bb35a17114e9..aaa964a27f23 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java @@ -23,7 +23,7 @@ public AerospikeClientInstrumentationModule() { @Override public ElementMatcher.Junction classLoaderMatcher() { - return hasClassesNamed("com.aerospike.client.AerospikeClient"); + return hasClassesNamed("com.aerospike.client.AerospikeClient").and(hasClassesNamed("com.aerospike.client.metrics.MetricsPolicy")); } @Override @@ -35,9 +35,4 @@ public List typeInstrumentations() { new AsyncHandlerInstrumentation(), new AsyncScanAllCommandInstrumentation()); } - - @Override - public boolean isIndyModule() { - return false; - } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java index 8e90ae8d5ac0..078adc5bad59 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java @@ -29,16 +29,11 @@ public void detachAndEnd() { contextThreadLocal.remove(); } - @SuppressWarnings("unchecked") public static AerospikeRequestContext current() { return contextThreadLocal.get(); } - public void endSpan( - Instrumenter instrumenter, - Context context, - AerospikeRequest request, - Throwable throwable) { + public void endSpan(Instrumenter instrumenter, Throwable throwable) { instrumenter.end(context, request, null, throwable); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java index 879340568a76..b0aa16fa4447 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java @@ -32,12 +32,14 @@ public final class AersopikeSingletons { INSTRUMENTATION_NAME, DbClientSpanNameExtractor.create(aerospikeDbAttributesGetter)) .addAttributesExtractor(DbClientAttributesExtractor.create(aerospikeDbAttributesGetter)) - .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) - .addOperationMetrics(AerospikeMetrics.get()); - if (InstrumentationConfig.get() - .getBoolean("otel.instrumentation.aerospike.experimental-span-attributes", false)) { + .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)); + InstrumentationConfig instrumentationConfig = InstrumentationConfig.get(); + if (instrumentationConfig.getBoolean("otel.instrumentation.aerospike.experimental-span-attributes", false)) { builder.addAttributesExtractor(new AerospikeClientAttributeExtractor()); } + if (instrumentationConfig.getBoolean("otel.instrumentation.aerospike.experimental-metrics", false)) { + builder.addOperationMetrics(AerospikeMetrics.get()); + } INSTRUMENTER = builder.buildInstrumenter(SpanKindExtractor.alwaysClient()); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java index f9c8717efd7b..146592d8978a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java @@ -62,7 +62,7 @@ public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Comma } else { request.setStatus(Status.FAILURE); } - requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); } } } @@ -80,7 +80,7 @@ public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Comma AerospikeRequest request = requestContext.getRequest(); Context context = requestContext.getContext(); request.setStatus(Status.FAILURE); - requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java index d705a74c1343..fa1328c9e667 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java @@ -92,7 +92,7 @@ public static void onExit( } else { request.setStatus(Status.FAILURE); } - requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); } } } @@ -112,7 +112,7 @@ public static void onExit( AerospikeRequest request = requestContext.getRequest(); Context context = requestContext.getContext(); request.setStatus(Status.FAILURE); - requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java index d50ffc9aa4da..0f68062a09a0 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java @@ -78,7 +78,7 @@ public static void stopSpan( request.setNode(node); if (throwable != null) { request.setStatus(FAILURE); - requestContext.endSpan(instrumenter(), requestContext.getContext(), request, throwable); + requestContext.endSpan(instrumenter(), throwable); requestContext.detachAndEnd(); } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java index 3e2009cbe009..8dd41e13f38a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java @@ -123,7 +123,7 @@ public static void stopSpan( scope.close(); if (requestContext != null) { - requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); requestContext.detachAndEnd(); } } @@ -159,7 +159,7 @@ public static AerospikeRequestContext onEnter( } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static AerospikeRequestContext stopSpan( + public static void stopSpan( @Advice.Thrown Throwable throwable, @Advice.Enter AerospikeRequestContext requestContext, @Advice.Local("otelAerospikeRequest") AerospikeRequest request, @@ -170,16 +170,14 @@ public static AerospikeRequestContext stopSpan( } else { request.setStatus(Status.SUCCESS); } - if (scope == null) { - return requestContext; + if (scope != null) { + scope.close(); } - scope.close(); if (requestContext != null) { - requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); requestContext.detachAndEnd(); } - return requestContext; } } @@ -195,7 +193,6 @@ public static AerospikeRequestContext onEnter( @Advice.Local("otelContext") Context context, @Advice.Local("otelScope") Scope scope) { Context parentContext = currentContext(); - request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), namespace, setName); if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { return null; @@ -206,7 +203,7 @@ public static AerospikeRequestContext onEnter( } @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static AerospikeRequestContext stopSpan( + public static void stopSpan( @Advice.Thrown Throwable throwable, @Advice.Enter AerospikeRequestContext requestContext, @Advice.Local("otelAerospikeRequest") AerospikeRequest request, @@ -217,16 +214,13 @@ public static AerospikeRequestContext stopSpan( } else { request.setStatus(Status.SUCCESS); } - if (scope == null) { - return requestContext; + if (scope != null) { + scope.close(); } - - scope.close(); if (requestContext != null) { - requestContext.endSpan(AersopikeSingletons.instrumenter(), context, request, throwable); + requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); requestContext.detachAndEnd(); } - return requestContext; } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java index dd066bf1076f..5f92cb7a7d8e 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java @@ -15,7 +15,6 @@ import com.aerospike.client.Bin; import com.aerospike.client.Key; import com.aerospike.client.Record; -import com.aerospike.client.async.EventLoops; import com.aerospike.client.async.EventPolicy; import com.aerospike.client.async.NioEventLoops; import com.aerospike.client.policy.ClientPolicy; @@ -62,11 +61,11 @@ static void setupSpec() { port = aerospikeServer.getMappedPort(3000); ClientPolicy clientPolicy = new ClientPolicy(); int eventLoopSize = Runtime.getRuntime().availableProcessors(); + System.out.println(eventLoopSize); EventPolicy eventPolicy = new EventPolicy(); eventPolicy.commandsPerEventLoop = 2; - EventLoops eventLoops = new NioEventLoops(eventPolicy, eventLoopSize); - clientPolicy.eventLoops = eventLoops; - clientPolicy.maxConnsPerNode = 11; + clientPolicy.eventLoops = new NioEventLoops(eventPolicy, eventLoopSize); + clientPolicy.maxConnsPerNode = eventLoopSize; clientPolicy.failIfNotConnected = true; aerospikeClient = new AerospikeClient(clientPolicy, "localhost", port); } From 0ef5f405099c21557c319486bec36e60bdf09502 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 11 Feb 2024 22:14:02 +0530 Subject: [PATCH 14/21] restructure the modules to v7.0.0 --- .../javaagent/build.gradle.kts | 2 +- .../v7_0}/AerospikeClientAttributeExtractor.java | 2 +- .../v7_0}/AerospikeClientInstrumentationModule.java | 7 ++++--- .../aerospike/v7_0}/AerospikeDbAttributesGetter.java | 2 +- .../v7_0}/AerospikeNetworkAttributesGetter.java | 2 +- .../aerospike/v7_0}/AerospikeRequest.java | 2 +- .../aerospike/v7_0}/AerospikeRequestContext.java | 2 +- .../aerospike/v7_0}/AerospikeSemanticAttributes.java | 2 +- .../aerospike/v7_0}/AersopikeSingletons.java | 12 +++++++----- .../aerospike/v7_0}/AsyncCommandInstrumentation.java | 4 ++-- .../aerospike/v7_0}/AsyncHandlerInstrumentation.java | 2 +- .../v7_0}/AsyncScanAllCommandInstrumentation.java | 2 +- .../aerospike/v7_0}/SocketInstrumentation.java | 6 +++--- .../instrumentation/aerospike/v7_0}/Status.java | 2 +- .../aerospike/v7_0}/SyncCommandInstrumentation.java | 2 +- .../v7_0}/metrics/AerospikeMessageSizeUtil.java | 4 ++-- .../aerospike/v7_0}/metrics/AerospikeMetrics.java | 4 ++-- .../v7_0}/metrics/AerospikeMetricsAdvice.java | 4 ++-- .../aerospike/v7_0}/AerospikeClientTest.java | 2 +- settings.gradle.kts | 2 +- 20 files changed, 35 insertions(+), 32 deletions(-) rename instrumentation/aerospike-client/{aerospike-client-7.1 => aerospike-client-7.0}/javaagent/build.gradle.kts (93%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeClientAttributeExtractor.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeClientInstrumentationModule.java (89%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeDbAttributesGetter.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeNetworkAttributesGetter.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeRequest.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeRequestContext.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeSemanticAttributes.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AersopikeSingletons.java (86%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AsyncCommandInstrumentation.java (98%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AsyncHandlerInstrumentation.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AsyncScanAllCommandInstrumentation.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/SocketInstrumentation.java (97%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/Status.java (98%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/SyncCommandInstrumentation.java (99%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/metrics/AerospikeMessageSizeUtil.java (91%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/metrics/AerospikeMetrics.java (98%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/metrics/AerospikeMetricsAdvice.java (98%) rename instrumentation/aerospike-client/{aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1 => aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0}/AerospikeClientTest.java (99%) diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts similarity index 93% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts index daf1a888ed37..314381d86c5b 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts @@ -12,7 +12,7 @@ muzzle { } dependencies { - library("com.aerospike:aerospike-client:7.1.0") + library("com.aerospike:aerospike-client:7.0.0") implementation("io.opentelemetry:opentelemetry-extension-incubator") compileOnly("com.google.auto.value:auto-value-annotations") diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java index 71cd93b1607f..ec9bbe25d907 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientAttributeExtractor.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import com.aerospike.client.AerospikeException; import com.aerospike.client.ResultCode; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java similarity index 89% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java index aaa964a27f23..f37a4ea5a42c 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static java.util.Arrays.asList; @@ -18,12 +18,13 @@ public class AerospikeClientInstrumentationModule extends InstrumentationModule { public AerospikeClientInstrumentationModule() { - super("aerospike-client", "aerospike-client-7.1.0"); + super("aerospike-client", "aerospike-client-7.0.0"); } @Override public ElementMatcher.Junction classLoaderMatcher() { - return hasClassesNamed("com.aerospike.client.AerospikeClient").and(hasClassesNamed("com.aerospike.client.metrics.MetricsPolicy")); + return hasClassesNamed("com.aerospike.client.AerospikeClient") + .and(hasClassesNamed("com.aerospike.client.metrics.MetricsPolicy")); } @Override diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeDbAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeDbAttributesGetter.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java index e08388d69718..b5d36ab89e26 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeDbAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; import javax.annotation.Nullable; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeNetworkAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeNetworkAttributesGetter.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java index 859181fb405a..a0a983df1840 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeNetworkAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import com.aerospike.client.cluster.Node; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequest.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequest.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequest.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequest.java index f64cd0de7d60..6e27b0bcdcfc 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import com.aerospike.client.Key; import com.aerospike.client.cluster.Node; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequestContext.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequestContext.java index 078adc5bad59..9972baa0963b 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeRequestContext.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequestContext.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeSemanticAttributes.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeSemanticAttributes.java index d9b6f5d66583..566ffe897c50 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeSemanticAttributes.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeSemanticAttributes.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java similarity index 86% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java index b0aa16fa4447..44dd57d6d899 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesExtractor; @@ -14,10 +14,10 @@ import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics.AerospikeMetrics; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics.AerospikeMetrics; public final class AersopikeSingletons { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.1"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.0"; private static final Instrumenter INSTRUMENTER; @@ -34,10 +34,12 @@ public final class AersopikeSingletons { .addAttributesExtractor(DbClientAttributesExtractor.create(aerospikeDbAttributesGetter)) .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)); InstrumentationConfig instrumentationConfig = InstrumentationConfig.get(); - if (instrumentationConfig.getBoolean("otel.instrumentation.aerospike.experimental-span-attributes", false)) { + if (instrumentationConfig.getBoolean( + "otel.instrumentation.aerospike.experimental-span-attributes", false)) { builder.addAttributesExtractor(new AerospikeClientAttributeExtractor()); } - if (instrumentationConfig.getBoolean("otel.instrumentation.aerospike.experimental-metrics", false)) { + if (instrumentationConfig.getBoolean( + "otel.instrumentation.aerospike.experimental-metrics", false)) { builder.addOperationMetrics(AerospikeMetrics.get()); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java similarity index 98% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java index c00962b82e5c..b12f6ceb112a 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isConstructor; import static net.bytebuddy.matcher.ElementMatchers.isPublic; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncHandlerInstrumentation.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncHandlerInstrumentation.java index 146592d8978a..4e656aedd411 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncHandlerInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncHandlerInstrumentation.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncScanAllCommandInstrumentation.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncScanAllCommandInstrumentation.java index fa1328c9e667..713ee701ab39 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AsyncScanAllCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncScanAllCommandInstrumentation.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; import static net.bytebuddy.matcher.ElementMatchers.isConstructor; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SocketInstrumentation.java similarity index 97% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SocketInstrumentation.java index 0f68062a09a0..cd4fb7bffff2 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SocketInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SocketInstrumentation.java @@ -3,10 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.Status.FAILURE; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.Status.FAILURE; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isProtected; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/Status.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/Status.java similarity index 98% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/Status.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/Status.java index 32ad873bbac0..e25708d6e015 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/Status.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/Status.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; public enum Status { SUCCESS, diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java index 8dd41e13f38a..504634808077 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/SyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; import static net.bytebuddy.matcher.ElementMatchers.isFinal; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMessageSizeUtil.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMessageSizeUtil.java similarity index 91% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMessageSizeUtil.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMessageSizeUtil.java index 939003497eca..3bae5407b42d 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMessageSizeUtil.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMessageSizeUtil.java @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AerospikeSemanticAttributes; import javax.annotation.Nullable; final class AerospikeMessageSizeUtil { diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetrics.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java similarity index 98% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetrics.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java index ec59462c36d3..f24e80f17f41 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetrics.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics.AerospikeMessageSizeUtil.getMessageSize; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics.AerospikeMessageSizeUtil.getMessageSize; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetricsAdvice.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java similarity index 98% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetricsAdvice.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java index 415f2a424198..1a2c8f32e710 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/metrics/AerospikeMetricsAdvice.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.metrics; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; @@ -13,7 +13,7 @@ import io.opentelemetry.extension.incubator.metrics.ExtendedLongCounterBuilder; import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder; import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_1.AerospikeSemanticAttributes; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AerospikeSemanticAttributes; import io.opentelemetry.semconv.SemanticAttributes; import java.util.ArrayList; import java.util.List; diff --git a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java similarity index 99% rename from instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java index 5f92cb7a7d8e..9469eac55fbd 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_1/AerospikeClientTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; diff --git a/settings.gradle.kts b/settings.gradle.kts index f56de38fc424..eba1328a3d38 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -138,7 +138,7 @@ include(":smoke-tests:images:spring-boot") include(":smoke-tests-otel-starter") -include(":instrumentation:aerospike-client:aerospike-client-7.1:javaagent") +include(":instrumentation:aerospike-client:aerospike-client-7.0:javaagent") include(":instrumentation:akka:akka-actor-2.3:javaagent") include(":instrumentation:akka:akka-actor-fork-join-2.5:javaagent") include(":instrumentation:akka:akka-http-10.0:javaagent") From 3a3e50986658ef8d968e4636f1f46d2158d32e7e Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 11 Feb 2024 22:19:56 +0530 Subject: [PATCH 15/21] adds readme for system properties --- instrumentation/aerospike-client/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 instrumentation/aerospike-client/README.md diff --git a/instrumentation/aerospike-client/README.md b/instrumentation/aerospike-client/README.md new file mode 100644 index 000000000000..35a6e816e959 --- /dev/null +++ b/instrumentation/aerospike-client/README.md @@ -0,0 +1,6 @@ +# Settings for the Aerospike-Client instrumentation + +| System property | Type | Default | Description | +|---------------------------------------------------------------|---------|---------|----------------------------------------------------------------------| +| `otel.instrumentation.aerospike.experimental-span-attributes` | Boolean | `false` | Enable the capture of experimental Aerospike client span attributes. | +| `otel.instrumentation.aerospike.experimental-metrics` | Boolean | `false` | Enable the recording of experimental Aerospike client metrics | From cc92b86571afd73dda1759fa56e802e1664270c4 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 26 Nov 2024 18:06:39 +0530 Subject: [PATCH 16/21] refactors aerospike module --- .../javaagent/build.gradle.kts | 4 +- .../AerospikeClientAttributeExtractor.java | 22 +- .../AerospikeClientInstrumentationModule.java | 9 +- .../v7_0/AerospikeDbAttributesGetter.java | 27 +- .../AerospikeNetworkAttributesGetter.java | 1 + .../aerospike/v7_0/AersopikeSingletons.java | 6 +- .../v7_0/AsyncCommandInstrumentation.java | 92 ++++-- .../v7_0/AsyncHandlerInstrumentation.java | 87 ----- .../AsyncScanAllCommandInstrumentation.java | 119 ------- .../v7_0/IAerospikeClientInstrumentation.java | 130 ++++++++ .../aerospike/v7_0/SocketInstrumentation.java | 87 ----- .../aerospike/v7_0/Status.java | 12 - .../v7_0/SyncCommandInstrumentation.java | 211 +----------- .../v7_0/{ => internal}/AerospikeRequest.java | 36 +- .../AerospikeRequestContext.java | 32 +- .../AerospikeSemanticAttributes.java | 20 +- .../v7_0/internal/CustomElementMatcher.java | 33 ++ .../metrics/AerospikeMessageSizeUtil.java | 32 -- .../v7_0/metrics/AerospikeMetrics.java | 33 -- .../v7_0/metrics/AerospikeMetricsAdvice.java | 109 ++---- .../aerospike/v7_0/AerospikeClientTest.java | 310 ++++-------------- 21 files changed, 425 insertions(+), 987 deletions(-) delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncHandlerInstrumentation.java delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncScanAllCommandInstrumentation.java create mode 100644 instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/IAerospikeClientInstrumentation.java delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SocketInstrumentation.java delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/Status.java rename instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/{ => internal}/AerospikeRequest.java (53%) rename instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/{ => internal}/AerospikeRequestContext.java (56%) rename instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/{ => internal}/AerospikeSemanticAttributes.java (54%) create mode 100644 instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java delete mode 100644 instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMessageSizeUtil.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts index 314381d86c5b..f25c6fcc9fc0 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts @@ -12,8 +12,8 @@ muzzle { } dependencies { - library("com.aerospike:aerospike-client:7.0.0") - implementation("io.opentelemetry:opentelemetry-extension-incubator") + implementation("com.aerospike:aerospike-client:7.0.0") + implementation("io.opentelemetry:opentelemetry-api-incubator") compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java index ec9bbe25d907..afcadac1599c 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java @@ -10,6 +10,8 @@ import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes; import javax.annotation.Nullable; final class AerospikeClientAttributeExtractor @@ -18,10 +20,7 @@ final class AerospikeClientAttributeExtractor @Override public void onStart( AttributesBuilder attributes, Context parentContext, AerospikeRequest aerospikeRequest) { - attributes.put( - AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, aerospikeRequest.getNamespace()); attributes.put(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, aerospikeRequest.getSet()); - attributes.put(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, aerospikeRequest.getUserKey()); } @Override @@ -31,22 +30,21 @@ public void onEnd( AerospikeRequest aerospikeRequest, @Nullable Void unused, @Nullable Throwable error) { - attributes.put( - AerospikeSemanticAttributes.AEROSPIKE_STATUS, aerospikeRequest.getStatus().name()); + if (aerospikeRequest.getNode() != null) { + String nodeName = aerospikeRequest.getNode().getName(); + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_NODE_NAME, nodeName); + } + if (error != null) { if (error instanceof AerospikeException) { AerospikeException aerospikeException = (AerospikeException) error; attributes.put( - AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, aerospikeException.getResultCode()); + AerospikeSemanticAttributes.AEROSPIKE_STATUS, aerospikeException.getResultCode()); } else { - attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, ResultCode.CLIENT_ERROR); + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_STATUS, ResultCode.CLIENT_ERROR); } } else { - attributes.put(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, ResultCode.OK); - if (aerospikeRequest.getSize() != null) { - attributes.put( - AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, aerospikeRequest.getSize()); - } + attributes.put(AerospikeSemanticAttributes.AEROSPIKE_STATUS, ResultCode.OK); } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java index f37a4ea5a42c..bd2b0caf3e95 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java @@ -23,17 +23,14 @@ public AerospikeClientInstrumentationModule() { @Override public ElementMatcher.Junction classLoaderMatcher() { - return hasClassesNamed("com.aerospike.client.AerospikeClient") - .and(hasClassesNamed("com.aerospike.client.metrics.MetricsPolicy")); + return hasClassesNamed("com.aerospike.client.IAerospikeClient"); } @Override public List typeInstrumentations() { return asList( + new IAerospikeClientInstrumentation(), new SyncCommandInstrumentation(), - new SocketInstrumentation(), - new AsyncCommandInstrumentation(), - new AsyncHandlerInstrumentation(), - new AsyncScanAllCommandInstrumentation()); + new AsyncCommandInstrumentation()); } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java index b5d36ab89e26..4de76bdeae70 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java @@ -6,38 +6,39 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes; import javax.annotation.Nullable; final class AerospikeDbAttributesGetter implements DbClientAttributesGetter { @Override - public String getSystem(AerospikeRequest request) { + public String getDbSystem(AerospikeRequest request) { return AerospikeSemanticAttributes.DbSystemValues.AEROSPIKE; } @Override - @Nullable - public String getUser(AerospikeRequest request) { - return null; + public String getDbOperationName(AerospikeRequest request) { + return request.getOperation(); } + @Nullable @Override - public String getName(AerospikeRequest request) { - return null; + public String getDbNamespace(AerospikeRequest request) { + return request.getNamespace(); } + @Deprecated + @Nullable @Override - public String getConnectionString(AerospikeRequest request) { + public String getUser(AerospikeRequest aerospikeRequest) { return null; } + @Deprecated + @Nullable @Override - public String getStatement(AerospikeRequest request) { + public String getConnectionString(AerospikeRequest aerospikeRequest) { return null; } - - @Override - public String getOperation(AerospikeRequest request) { - return request.getOperation(); - } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java index a0a983df1840..affb07b68a9b 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java @@ -7,6 +7,7 @@ import com.aerospike.client.cluster.Node; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; import java.net.InetSocketAddress; import javax.annotation.Nullable; diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java index 44dd57d6d899..ce2b6619f082 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig; import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesExtractor; import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientSpanNameExtractor; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; @@ -13,7 +14,8 @@ import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; +import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics.AerospikeMetrics; public final class AersopikeSingletons { @@ -33,7 +35,7 @@ public final class AersopikeSingletons { DbClientSpanNameExtractor.create(aerospikeDbAttributesGetter)) .addAttributesExtractor(DbClientAttributesExtractor.create(aerospikeDbAttributesGetter)) .addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)); - InstrumentationConfig instrumentationConfig = InstrumentationConfig.get(); + InstrumentationConfig instrumentationConfig = AgentInstrumentationConfig.get(); if (instrumentationConfig.getBoolean( "otel.instrumentation.aerospike.experimental-span-attributes", false)) { builder.addAttributesExtractor(new AerospikeClientAttributeExtractor()); diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java index b12f6ceb112a..a5e8c4091be8 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java @@ -5,21 +5,21 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; -import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isConstructor; +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.takesGenericArguments; -import com.aerospike.client.Key; +import com.aerospike.client.AerospikeException; +import com.aerospike.client.cluster.Node; import com.aerospike.client.command.Command; -import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.util.VirtualField; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import java.util.Locale; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequestContext; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; @@ -40,39 +40,87 @@ public ElementMatcher typeMatcher() { public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( isConstructor().and(isPublic()), this.getClass().getName() + "$ConstructorAdvice"); + + transformer.applyAdviceToMethod( + isMethod().and(named("getNode")), this.getClass().getName() + "$GetNodeAdvice"); + + transformer.applyAdviceToMethod( + isMethod().and(named("onSuccess")), this.getClass().getName() + "$GetOnSuccessAdvice"); + + transformer.applyAdviceToMethod( + isMethod().and(named("onFailure").and(takesGenericArguments(AerospikeException.class))), + this.getClass().getName() + "$GetOnFailureAdvice"); } @SuppressWarnings("unused") public static class ConstructorAdvice { + @Advice.OnMethodExit(suppress = Throwable.class) - public static void onExit(@Advice.This Command command, @Advice.AllArguments Object[] objects) { - Key key = null; - for (Object object : objects) { - if (object instanceof Key) { - key = (Key) object; - break; - } + public static void getCommand(@Advice.This Command command) { + VirtualField virtualField = + VirtualField.find(Command.class, AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(command); + // If the AerospikeRequestContext is already there in VirtualField then we do not need + // to override it when constructor of other subclasses of AsyncCommand executes as + // AsyncCommand follows multilevel inheritance. + if (requestContext != null) { + return; } - if (key == null) { + requestContext = AerospikeRequestContext.current(); + if (requestContext == null) { return; } + virtualField.set(command, requestContext); + requestContext.detachContext(); + } + } + + @SuppressWarnings("unused") + public static class GetNodeAdvice { + + @Advice.OnMethodExit(suppress = Throwable.class) + public static void getNode(@Advice.Return Node node, @Advice.This Command command) { VirtualField virtualField = VirtualField.find(Command.class, AerospikeRequestContext.class); AerospikeRequestContext requestContext = virtualField.get(command); - if (requestContext != null) { + if (requestContext == null || requestContext.getRequest().getNode() != null) { return; } - Context parentContext = currentContext(); - AerospikeRequest request = - AerospikeRequest.create(command.getClass().getSimpleName().toUpperCase(Locale.ROOT), key); - if (!instrumenter().shouldStart(parentContext, request)) { + requestContext.getRequest().setNode(node); + } + } + + @SuppressWarnings("unused") + public static class GetOnSuccessAdvice { + + @Advice.OnMethodExit(suppress = Throwable.class) + public static void stopInstrumentation(@Advice.This Command command) { + VirtualField virtualField = + VirtualField.find(Command.class, AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(command); + if (requestContext == null) { return; } - Context context = instrumenter().start(parentContext, request); - AerospikeRequestContext aerospikeRequestContext = - AerospikeRequestContext.attach(request, context); + virtualField.set(command, null); + requestContext.endSpan(); + } + } + + @SuppressWarnings("unused") + public static class GetOnFailureAdvice { - virtualField.set(command, aerospikeRequestContext); + @Advice.OnMethodExit(suppress = Throwable.class) + public static void stopInstrumentation( + @Advice.Argument(0) AerospikeException ae, @Advice.This Command command) { + VirtualField virtualField = + VirtualField.find(Command.class, AerospikeRequestContext.class); + AerospikeRequestContext requestContext = virtualField.get(command); + if (requestContext == null) { + return; + } + virtualField.set(command, null); + requestContext.setThrowable(ae); + requestContext.endSpan(); } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncHandlerInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncHandlerInstrumentation.java deleted file mode 100644 index 4e656aedd411..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncHandlerInstrumentation.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; - -import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; -import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; -import static net.bytebuddy.matcher.ElementMatchers.isProtected; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; - -import com.aerospike.client.command.Command; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.util.VirtualField; -import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; -import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import net.bytebuddy.asm.Advice; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.matcher.ElementMatcher; - -public class AsyncHandlerInstrumentation implements TypeInstrumentation { - - @Override - public ElementMatcher classLoaderOptimization() { - return hasClassesNamed("com.aerospike.client.command.Command"); - } - - @Override - public ElementMatcher typeMatcher() { - return hasSuperClass(named("com.aerospike.client.command.Command")); - } - - @Override - public void transform(TypeTransformer transformer) { - transformer.applyAdviceToMethod( - named("onSuccess").and(takesNoArguments()).and(isProtected()), - this.getClass().getName() + "$OnSuccessAdvice"); - transformer.applyAdviceToMethod( - named("onFailure") - .and(takesArgument(0, named("com.aerospike.client.AerospikeException"))) - .and(isProtected()), - this.getClass().getName() + "$OnFailureAdvice"); - } - - @SuppressWarnings("unused") - public static class OnSuccessAdvice { - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Command command) { - VirtualField virtualField = - VirtualField.find(Command.class, AerospikeRequestContext.class); - AerospikeRequestContext requestContext = virtualField.get(command); - virtualField.set(command, null); - if (requestContext != null) { - AerospikeRequest request = requestContext.getRequest(); - Context context = requestContext.getContext(); - if (throwable == null) { - request.setStatus(Status.SUCCESS); - } else { - request.setStatus(Status.FAILURE); - } - requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); - } - } - } - - @SuppressWarnings("unused") - public static class OnFailureAdvice { - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void onExit(@Advice.Thrown Throwable throwable, @Advice.This Command command) { - VirtualField virtualField = - VirtualField.find(Command.class, AerospikeRequestContext.class); - AerospikeRequestContext requestContext = virtualField.get(command); - virtualField.set(command, null); - if (requestContext != null) { - AerospikeRequest request = requestContext.getRequest(); - Context context = requestContext.getContext(); - request.setStatus(Status.FAILURE); - requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); - } - } - } -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncScanAllCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncScanAllCommandInstrumentation.java deleted file mode 100644 index 713ee701ab39..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncScanAllCommandInstrumentation.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; - -import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; -import static net.bytebuddy.matcher.ElementMatchers.isConstructor; -import static net.bytebuddy.matcher.ElementMatchers.isProtected; -import static net.bytebuddy.matcher.ElementMatchers.isPublic; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; - -import com.aerospike.client.async.AsyncScanPartitionExecutor; -import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.util.VirtualField; -import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; -import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import java.util.Locale; -import net.bytebuddy.asm.Advice; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.matcher.ElementMatcher; - -public class AsyncScanAllCommandInstrumentation implements TypeInstrumentation { - @Override - public ElementMatcher typeMatcher() { - return named("com.aerospike.client.async.AsyncScanPartitionExecutor"); - } - - @Override - public void transform(TypeTransformer transformer) { - transformer.applyAdviceToMethod( - isConstructor().and(isPublic()), this.getClass().getName() + "$ConstructorAdvice"); - transformer.applyAdviceToMethod( - named("onSuccess").and(takesNoArguments()).and(isProtected()), - this.getClass().getName() + "$OnSuccessAdvice"); - transformer.applyAdviceToMethod( - named("onFailure") - .and(takesArgument(0, named("com.aerospike.client.AerospikeException"))) - .and(isProtected()), - this.getClass().getName() + "$OnFailureAdvice"); - } - - @SuppressWarnings("unused") - public static class ConstructorAdvice { - @Advice.OnMethodExit(suppress = Throwable.class) - public static void onExit( - @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor, - @Advice.Argument(4) String namespace, - @Advice.Argument(5) String setName) { - VirtualField virtualField = - VirtualField.find(AsyncScanPartitionExecutor.class, AerospikeRequestContext.class); - AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); - if (requestContext != null) { - return; - } - Context parentContext = currentContext(); - AerospikeRequest request = - AerospikeRequest.create( - asyncScanPartitionExecutor.getClass().getSimpleName().toUpperCase(Locale.ROOT), - namespace, - setName); - if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { - return; - } - Context context = AersopikeSingletons.instrumenter().start(parentContext, request); - AerospikeRequestContext aerospikeRequestContext = - AerospikeRequestContext.attach(request, context); - - virtualField.set(asyncScanPartitionExecutor, aerospikeRequestContext); - } - } - - @SuppressWarnings("unused") - public static class OnSuccessAdvice { - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void onExit( - @Advice.Thrown Throwable throwable, - @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor) { - VirtualField virtualField = - VirtualField.find(AsyncScanPartitionExecutor.class, AerospikeRequestContext.class); - AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); - virtualField.set(asyncScanPartitionExecutor, null); - if (requestContext != null) { - AerospikeRequest request = requestContext.getRequest(); - Context context = requestContext.getContext(); - if (throwable == null) { - request.setStatus(Status.SUCCESS); - } else { - request.setStatus(Status.FAILURE); - } - requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); - } - } - } - - @SuppressWarnings("unused") - public static class OnFailureAdvice { - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void onExit( - @Advice.Thrown Throwable throwable, - @Advice.This AsyncScanPartitionExecutor asyncScanPartitionExecutor) { - VirtualField virtualField = - VirtualField.find(AsyncScanPartitionExecutor.class, AerospikeRequestContext.class); - AerospikeRequestContext requestContext = virtualField.get(asyncScanPartitionExecutor); - virtualField.set(asyncScanPartitionExecutor, null); - if (requestContext != null) { - AerospikeRequest request = requestContext.getRequest(); - Context context = requestContext.getContext(); - request.setStatus(Status.FAILURE); - requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); - } - } - } -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/IAerospikeClientInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/IAerospikeClientInstrumentation.java new file mode 100644 index 000000000000..7712c1405852 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/IAerospikeClientInstrumentation.java @@ -0,0 +1,130 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; + +import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.CustomElementMatcher.argumentOfType; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.CustomElementMatcher.iterableHasAtLeastOne; +import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; +import static net.bytebuddy.matcher.ElementMatchers.isMethod; +import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; +import static net.bytebuddy.matcher.ElementMatchers.takesGenericArguments; + +import com.aerospike.client.AerospikeException; +import com.aerospike.client.Key; +import com.aerospike.client.async.EventLoop; +import io.opentelemetry.context.Context; +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequestContext; +import java.util.Locale; +import net.bytebuddy.asm.Advice; +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +public class IAerospikeClientInstrumentation implements TypeInstrumentation { + @Override + public ElementMatcher typeMatcher() { + return hasSuperType(named("com.aerospike.client.IAerospikeClient")); + } + + @Override + public void transform(TypeTransformer transformer) { + transformer.applyAdviceToMethod( + isMethod() + .and(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(Key.class)))) + .and( + not(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(EventLoop.class))))), + this.getClass().getName() + "$SyncCommandAdvice"); + + transformer.applyAdviceToMethod( + isMethod() + .and(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(Key.class)))) + .and(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(EventLoop.class)))), + this.getClass().getName() + "$AsyncCommandAdvice"); + } + + @SuppressWarnings("unused") + public static class SyncCommandAdvice { + + @Advice.OnMethodEnter(suppress = AerospikeException.class) + public static void startInstrumentation( + @Advice.Origin("#m") String methodName, + @Advice.AllArguments Object[] args, + @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { + Key key = null; + for (Object object : args) { + if (object instanceof Key) { + key = (Key) object; + } + } + if (key == null) { + return; + } + Context parentContext = currentContext(); + AerospikeRequest request = + AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key.namespace, key.setName); + if (!instrumenter().shouldStart(parentContext, request)) { + return; + } + Context context = instrumenter().start(parentContext, request); + requestContext = AerospikeRequestContext.attach(request, context); + } + + @Advice.OnMethodExit( + onThrowable = AerospikeException.class, + suppress = AerospikeException.class) + public static void stopInstrumentation( + @Advice.Thrown AerospikeException ae, + @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { + requestContext.setThrowable(ae); + requestContext.detachAndEnd(); + } + } + + @SuppressWarnings("unused") + public static class AsyncCommandAdvice { + + @Advice.OnMethodEnter(suppress = AerospikeException.class) + public static void startInstrumentation( + @Advice.Origin("#m") String methodName, + @Advice.AllArguments Object[] args, + @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { + Key key = null; + for (Object object : args) { + if (object instanceof Key) { + key = (Key) object; + } + } + if (key == null) { + return; + } + Context parentContext = currentContext(); + AerospikeRequest request = + AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key.namespace, key.setName); + if (!instrumenter().shouldStart(parentContext, request)) { + return; + } + Context context = instrumenter().start(parentContext, request); + requestContext = AerospikeRequestContext.attach(request, context); + } + + @Advice.OnMethodExit( + onThrowable = AerospikeException.class, + suppress = AerospikeException.class) + public static void stopInstrumentaionIfError( + @Advice.Thrown AerospikeException ae, + @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { + if (ae != null) { + requestContext.setThrowable(ae); + requestContext.detachAndEnd(); + } + } + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SocketInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SocketInstrumentation.java deleted file mode 100644 index cd4fb7bffff2..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SocketInstrumentation.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; - -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.Status.FAILURE; -import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; -import static net.bytebuddy.matcher.ElementMatchers.isMethod; -import static net.bytebuddy.matcher.ElementMatchers.isProtected; -import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.returns; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import static net.bytebuddy.matcher.ElementMatchers.takesNoArguments; - -import com.aerospike.client.cluster.Node; -import com.aerospike.client.command.Command; -import io.opentelemetry.instrumentation.api.util.VirtualField; -import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; -import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import net.bytebuddy.asm.Advice; -import net.bytebuddy.description.type.TypeDescription; -import net.bytebuddy.matcher.ElementMatcher; - -public class SocketInstrumentation implements TypeInstrumentation { - - @Override - public ElementMatcher typeMatcher() { - return hasSuperClass(named("com.aerospike.client.command.Command")); - } - - @Override - public void transform(TypeTransformer transformer) { - transformer.applyAdviceToMethod( - isMethod() - .and(isProtected()) - .and(named("getNode")) - .and(returns(named("com.aerospike.client.cluster.Node"))) - .and(takesNoArguments()), - this.getClass().getName() + "$NodeSyncCommandAdvice"); - - transformer.applyAdviceToMethod( - isMethod() - .and(named("getNode")) - .and(returns(named("com.aerospike.client.cluster.Node"))) - .and(takesArgument(0, named("com.aerospike.client.cluster.Cluster"))), - this.getClass().getName() + "$NodeAsyncCommandAdvice"); - } - - @SuppressWarnings("unused") - public static class NodeSyncCommandAdvice { - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan(@Advice.Return Node node) { - AerospikeRequestContext context = AerospikeRequestContext.current(); - if (context != null) { - AerospikeRequest request = context.getRequest(); - request.setNode(node); - } - } - } - - @SuppressWarnings("unused") - public static class NodeAsyncCommandAdvice { - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan( - @Advice.Thrown Throwable throwable, - @Advice.Return Node node, - @Advice.This Command command) { - VirtualField virtualField = - VirtualField.find(Command.class, AerospikeRequestContext.class); - AerospikeRequestContext requestContext = virtualField.get(command); - if (requestContext != null) { - AerospikeRequest request = requestContext.getRequest(); - request.setNode(node); - if (throwable != null) { - request.setStatus(FAILURE); - requestContext.endSpan(instrumenter(), throwable); - requestContext.detachAndEnd(); - } - } - } - } -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/Status.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/Status.java deleted file mode 100644 index e25708d6e015..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/Status.java +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; - -public enum Status { - SUCCESS, - FAILURE, - RECORD_NOT_FOUND; -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java index 504634808077..af9e0ef0b669 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java @@ -5,222 +5,47 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; -import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; -import static net.bytebuddy.matcher.ElementMatchers.isFinal; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; +import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; import static net.bytebuddy.matcher.ElementMatchers.isMethod; -import static net.bytebuddy.matcher.ElementMatchers.isPublic; -import static net.bytebuddy.matcher.ElementMatchers.isStatic; import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.not; -import static net.bytebuddy.matcher.ElementMatchers.returns; -import static net.bytebuddy.matcher.ElementMatchers.takesArgument; -import com.aerospike.client.Key; -import com.aerospike.client.Record; -import io.opentelemetry.context.Context; -import io.opentelemetry.context.Scope; +import com.aerospike.client.cluster.Node; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import java.util.Locale; +import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequestContext; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; public class SyncCommandInstrumentation implements TypeInstrumentation { + + @Override + public ElementMatcher classLoaderOptimization() { + return hasClassesNamed("com.aerospike.client.command.SyncCommand"); + } + @Override public ElementMatcher typeMatcher() { - return named("com.aerospike.client.AerospikeClient"); + return hasSuperClass(named("com.aerospike.client.command.SyncCommand")); } @Override public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( - isMethod() - .and(isPublic()) - .and(not(isStatic())) - .and(isFinal()) - .and(takesArgument(1, named("com.aerospike.client.Key"))) - .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))) - .and(returns(named("com.aerospike.client.Record"))), - this.getClass().getName() + "$SyncReturnCommandAdvice"); - - transformer.applyAdviceToMethod( - isMethod() - .and(isPublic()) - .and(not(isStatic())) - .and(isFinal()) - .and(takesArgument(1, named("com.aerospike.client.Key"))) - .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))) - .and(not(returns(named("com.aerospike.client.Record")))), - this.getClass().getName() + "$SyncNonReturnCommandAdvice"); - - transformer.applyAdviceToMethod( - isMethod() - .and(isPublic()) - .and(not(isStatic())) - .and(isFinal()) - .and(named("scanAll")) - .and(not(takesArgument(0, named("com.aerospike.client.async.EventLoop")))), - this.getClass().getName() + "$SyncScanAllCommandAdvice"); + isMethod().and(named("getNode")), this.getClass().getName() + "$GetNodeAdvice"); } @SuppressWarnings("unused") - public static class SyncReturnCommandAdvice { + public static class GetNodeAdvice { - @Advice.OnMethodEnter(suppress = Throwable.class) - public static AerospikeRequestContext onEnter( - @Advice.Origin("#m") String methodName, - @Advice.AllArguments Object[] keys, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - Context parentContext = currentContext(); - Key key = null; - for (Object object : keys) { - if (object instanceof Key) { - key = (Key) object; - } - } - if (key == null) { - return null; - } - request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key); - if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { - return null; - } - context = AersopikeSingletons.instrumenter().start(parentContext, request); - scope = context.makeCurrent(); - return AerospikeRequestContext.attach(request, context); - } - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan( - @Advice.Return Record record, - @Advice.Thrown Throwable throwable, - @Advice.Enter AerospikeRequestContext requestContext, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (throwable != null) { - request.setStatus(Status.FAILURE); - } else if (record == null) { - request.setStatus(Status.RECORD_NOT_FOUND); - } else { - request.setStatus(Status.SUCCESS); - } - if (record == null || record.bins.isEmpty()) { - request.setSize(0); - } else { - int size = 0; - for (Object value : record.bins.values()) { - size += ((String) value).length(); - } - request.setSize(size); - } - if (scope == null) { + @Advice.OnMethodExit(suppress = Throwable.class) + public static void getNode(@Advice.Return Node node) { + AerospikeRequestContext requestContext = AerospikeRequestContext.current(); + if (requestContext == null || requestContext.getRequest().getNode() != null) { return; } - - scope.close(); - if (requestContext != null) { - requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); - requestContext.detachAndEnd(); - } - } - } - - @SuppressWarnings("unused") - public static class SyncNonReturnCommandAdvice { - - @Advice.OnMethodEnter(suppress = Throwable.class) - public static AerospikeRequestContext onEnter( - @Advice.Origin("#m") String methodName, - @Advice.AllArguments Object[] keys, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - Context parentContext = currentContext(); - Key key = null; - for (Object object : keys) { - if (object instanceof Key) { - key = (Key) object; - } - } - if (key == null) { - return null; - } - request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), key); - if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { - return null; - } - context = AersopikeSingletons.instrumenter().start(parentContext, request); - scope = context.makeCurrent(); - return AerospikeRequestContext.attach(request, context); - } - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan( - @Advice.Thrown Throwable throwable, - @Advice.Enter AerospikeRequestContext requestContext, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (throwable != null) { - request.setStatus(Status.FAILURE); - } else { - request.setStatus(Status.SUCCESS); - } - if (scope != null) { - scope.close(); - } - - if (requestContext != null) { - requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); - requestContext.detachAndEnd(); - } - } - } - - @SuppressWarnings("unused") - public static class SyncScanAllCommandAdvice { - - @Advice.OnMethodEnter(suppress = Throwable.class) - public static AerospikeRequestContext onEnter( - @Advice.Origin("#m") String methodName, - @Advice.Argument(1) String namespace, - @Advice.Argument(2) String setName, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - Context parentContext = currentContext(); - request = AerospikeRequest.create(methodName.toUpperCase(Locale.ROOT), namespace, setName); - if (!AersopikeSingletons.instrumenter().shouldStart(parentContext, request)) { - return null; - } - context = AersopikeSingletons.instrumenter().start(parentContext, request); - scope = context.makeCurrent(); - return AerospikeRequestContext.attach(request, context); - } - - @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) - public static void stopSpan( - @Advice.Thrown Throwable throwable, - @Advice.Enter AerospikeRequestContext requestContext, - @Advice.Local("otelAerospikeRequest") AerospikeRequest request, - @Advice.Local("otelContext") Context context, - @Advice.Local("otelScope") Scope scope) { - if (throwable != null) { - request.setStatus(Status.FAILURE); - } else { - request.setStatus(Status.SUCCESS); - } - if (scope != null) { - scope.close(); - } - if (requestContext != null) { - requestContext.endSpan(AersopikeSingletons.instrumenter(), throwable); - requestContext.detachAndEnd(); - } + requestContext.getRequest().setNode(node); } } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequest.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java similarity index 53% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequest.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java index 6e27b0bcdcfc..47cc7d84fc61 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java @@ -3,26 +3,21 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; -import com.aerospike.client.Key; import com.aerospike.client.cluster.Node; import com.google.auto.value.AutoValue; -import javax.annotation.Nullable; +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ @AutoValue public abstract class AerospikeRequest { private Node node; - private Integer size; - private Status status; - - public static AerospikeRequest create(String operation, Key key) { - return new AutoValue_AerospikeRequest( - operation, key.namespace, key.setName, key.userKey.toString()); - } public static AerospikeRequest create(String operation, String namespace, String set) { - return new AutoValue_AerospikeRequest(operation, namespace, set, null); + return new AutoValue_AerospikeRequest(operation, namespace, set); } public abstract String getOperation(); @@ -31,9 +26,6 @@ public static AerospikeRequest create(String operation, String namespace, String public abstract String getSet(); - @Nullable - public abstract String getUserKey(); - public void setNode(Node node) { this.node = node; } @@ -41,20 +33,4 @@ public void setNode(Node node) { public Node getNode() { return this.node; } - - public Integer getSize() { - return size; - } - - public void setSize(Integer size) { - this.size = size; - } - - public Status getStatus() { - return status; - } - - public void setStatus(Status status) { - this.status = status; - } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequestContext.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java similarity index 56% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequestContext.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java index 9972baa0963b..f3460e09ef9b 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeRequestContext.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java @@ -3,22 +3,31 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; + +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; import io.opentelemetry.context.Context; -import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ public final class AerospikeRequestContext { private static final ThreadLocal contextThreadLocal = new ThreadLocal<>(); private AerospikeRequest request; private Context context; + private Throwable throwable; private AerospikeRequestContext() {} public static AerospikeRequestContext attach(AerospikeRequest request, Context context) { - - AerospikeRequestContext requestContext = new AerospikeRequestContext(); + AerospikeRequestContext requestContext = current(); + if (requestContext != null) { + requestContext.detachContext(); + } + requestContext = new AerospikeRequestContext(); requestContext.request = request; requestContext.context = context; contextThreadLocal.set(requestContext); @@ -26,6 +35,13 @@ public static AerospikeRequestContext attach(AerospikeRequest request, Context c } public void detachAndEnd() { + detachContext(); + if (request != null) { + endSpan(); + } + } + + public void detachContext() { contextThreadLocal.remove(); } @@ -33,15 +49,15 @@ public static AerospikeRequestContext current() { return contextThreadLocal.get(); } - public void endSpan(Instrumenter instrumenter, Throwable throwable) { - instrumenter.end(context, request, null, throwable); + public void endSpan() { + instrumenter().end(context, request, null, throwable); } public AerospikeRequest getRequest() { return request; } - public Context getContext() { - return context; + public void setThrowable(Throwable throwable) { + this.throwable = throwable; } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeSemanticAttributes.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java similarity index 54% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeSemanticAttributes.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java index 566ffe897c50..2edd54778674 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeSemanticAttributes.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java @@ -3,24 +3,28 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; import io.opentelemetry.api.common.AttributeKey; +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ public final class AerospikeSemanticAttributes { private AerospikeSemanticAttributes() {} - public static final AttributeKey AEROSPIKE_STATUS = stringKey("aerospike.status"); - public static final AttributeKey AEROSPIKE_ERROR_CODE = longKey("aerospike.error.code"); - public static final AttributeKey AEROSPIKE_NAMESPACE = stringKey("aerospike.namespace"); - public static final AttributeKey AEROSPIKE_SET_NAME = stringKey("aerospike.set.name"); - public static final AttributeKey AEROSPIKE_USER_KEY = stringKey("aerospike.user.key"); - public static final AttributeKey AEROSPIKE_TRANSFER_SIZE = - longKey("aerospike.transfer.size"); + public static final AttributeKey AEROSPIKE_STATUS = longKey("db.status"); + public static final AttributeKey AEROSPIKE_SET_NAME = stringKey("db.set.name"); + public static final AttributeKey AEROSPIKE_NODE_NAME = stringKey("db.node.name"); + /** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ public static final class DbSystemValues { public static final String AEROSPIKE = "aerospike"; diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java new file mode 100644 index 000000000000..628d871e9837 --- /dev/null +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java @@ -0,0 +1,33 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; + +import net.bytebuddy.description.type.TypeDescription; +import net.bytebuddy.matcher.ElementMatcher; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class CustomElementMatcher { + private CustomElementMatcher() {} + + public static ElementMatcher> iterableHasAtLeastOne( + ElementMatcher matcher) { + return iterable -> { + for (TypeDescription.Generic typeDescription : iterable) { + if (matcher.matches(typeDescription)) { + return true; + } + } + return false; + }; + } + + public static ElementMatcher argumentOfType(Class clazz) { + return typeDescription -> typeDescription.asErasure().represents(clazz); + } +} diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMessageSizeUtil.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMessageSizeUtil.java deleted file mode 100644 index 3bae5407b42d..000000000000 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMessageSizeUtil.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AerospikeSemanticAttributes; -import javax.annotation.Nullable; - -final class AerospikeMessageSizeUtil { - - @Nullable - static Long getMessageSize(Attributes... attributesList) { - return getAttribute(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, attributesList); - } - - @Nullable - private static T getAttribute(AttributeKey key, Attributes... attributesList) { - for (Attributes attributes : attributesList) { - T value = attributes.get(key); - if (value != null) { - return value; - } - } - return null; - } - - private AerospikeMessageSizeUtil() {} -} diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java index f24e80f17f41..54f10f3219f2 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java @@ -5,15 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics.AerospikeMessageSizeUtil.getMessageSize; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; -import io.opentelemetry.api.metrics.LongCounter; -import io.opentelemetry.api.metrics.LongCounterBuilder; import io.opentelemetry.api.metrics.LongUpDownCounter; import io.opentelemetry.api.metrics.LongUpDownCounterBuilder; import io.opentelemetry.api.metrics.Meter; @@ -32,27 +29,11 @@ public final class AerospikeMetrics implements OperationListener { private static final Logger logger = Logger.getLogger(AerospikeMetrics.class.getName()); - private final LongCounter requestCounter; - - private final LongCounter responseCounter; - private final LongUpDownCounter concurrencyUpDownCounter; private final DoubleHistogram clientLatencyHistogram; - private final DoubleHistogram recordSizeHistogram; - private AerospikeMetrics(Meter meter) { - LongCounterBuilder requestCounterBuilder = - meter.counterBuilder("aerospike.requests").setDescription("Aerospike Calls"); - AerospikeMetricsAdvice.applyRequestCounterAdvice(requestCounterBuilder); - requestCounter = requestCounterBuilder.build(); - - LongCounterBuilder responseCounterBuilder = - meter.counterBuilder("aerospike.response").setDescription("Aerospike Responses"); - AerospikeMetricsAdvice.applyResponseCounterAdvice(responseCounterBuilder); - responseCounter = responseCounterBuilder.build(); - LongUpDownCounterBuilder concurrencyUpDownCounterBuilder = meter .upDownCounterBuilder("aerospike.concurrency") @@ -67,14 +48,6 @@ private AerospikeMetrics(Meter meter) { .setUnit("ms"); AerospikeMetricsAdvice.applyClientDurationAdvice(durationBuilder); clientLatencyHistogram = durationBuilder.build(); - - DoubleHistogramBuilder recordSizeHistogramBuilder = - meter - .histogramBuilder("aerospike.record.size") - .setDescription("Aerospike Record Size") - .setUnit("By"); - AerospikeMetricsAdvice.applyRecordSizeAdvice(recordSizeHistogramBuilder); - recordSizeHistogram = recordSizeHistogramBuilder.build(); } public static OperationMetrics get() { @@ -83,7 +56,6 @@ public static OperationMetrics get() { @Override public Context onStart(Context context, Attributes startAttributes, long startNanos) { - requestCounter.add(1, startAttributes, context); concurrencyUpDownCounter.add(1, startAttributes, context); return context.with( AEROSPIKE_CLIENT_METRICS_STATE, @@ -102,13 +74,8 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } concurrencyUpDownCounter.add(-1, state.startAttributes(), context); Attributes mergedAttributes = state.startAttributes().toBuilder().putAll(endAttributes).build(); - responseCounter.add(1, mergedAttributes, context); clientLatencyHistogram.record( (endNanos - state.startTimeNanos()) / NANOS_PER_MS, mergedAttributes, context); - Long requestBodySize = getMessageSize(mergedAttributes); - if (requestBodySize != null) { - recordSizeHistogram.record(requestBodySize, mergedAttributes, context); - } } @AutoValue diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java index 1a2c8f32e710..23eff543d220 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java @@ -5,114 +5,57 @@ package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes.AEROSPIKE_NODE_NAME; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes.AEROSPIKE_SET_NAME; +import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes.AEROSPIKE_STATUS; +import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; +import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT; +import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM; + import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.incubator.metrics.ExtendedDoubleHistogramBuilder; +import io.opentelemetry.api.incubator.metrics.ExtendedLongUpDownCounterBuilder; import io.opentelemetry.api.metrics.DoubleHistogramBuilder; -import io.opentelemetry.api.metrics.LongCounterBuilder; import io.opentelemetry.api.metrics.LongUpDownCounterBuilder; -import io.opentelemetry.extension.incubator.metrics.ExtendedDoubleHistogramBuilder; -import io.opentelemetry.extension.incubator.metrics.ExtendedLongCounterBuilder; -import io.opentelemetry.extension.incubator.metrics.ExtendedLongUpDownCounterBuilder; -import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AerospikeSemanticAttributes; -import io.opentelemetry.semconv.SemanticAttributes; import java.util.ArrayList; import java.util.List; +@SuppressWarnings("deprecation") // using deprecated semconv final class AerospikeMetricsAdvice { private AerospikeMetricsAdvice() {} - static void applyRequestCounterAdvice(LongCounterBuilder builder) { - if (!(builder instanceof ExtendedLongCounterBuilder)) { - return; - } - - List> attributes = new ArrayList<>(); - attributes.add(SemanticAttributes.DB_SYSTEM); - attributes.add(SemanticAttributes.DB_OPERATION); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(NetworkAttributes.NETWORK_PEER_PORT); - attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); - - ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); - } - static void applyConcurrencyUpDownCounterAdvice(LongUpDownCounterBuilder builder) { if (!(builder instanceof ExtendedLongUpDownCounterBuilder)) { return; } List> attributes = new ArrayList<>(); - attributes.add(SemanticAttributes.DB_SYSTEM); - attributes.add(SemanticAttributes.DB_OPERATION); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(NetworkAttributes.NETWORK_PEER_PORT); - attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); + attributes.add(DB_SYSTEM); + attributes.add(DB_OPERATION); + attributes.add(DB_NAME); + attributes.add(AEROSPIKE_SET_NAME); ((ExtendedLongUpDownCounterBuilder) builder).setAttributesAdvice(attributes); } - static void applyResponseCounterAdvice(LongCounterBuilder builder) { - if (!(builder instanceof ExtendedLongCounterBuilder)) { - return; - } - - List> attributes = new ArrayList<>(); - attributes.add(SemanticAttributes.DB_SYSTEM); - attributes.add(SemanticAttributes.DB_OPERATION); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(NetworkAttributes.NETWORK_PEER_PORT); - attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); - - ((ExtendedLongCounterBuilder) builder).setAttributesAdvice(attributes); - } - static void applyClientDurationAdvice(DoubleHistogramBuilder builder) { if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { return; } List> attributes = new ArrayList<>(); - attributes.add(SemanticAttributes.DB_SYSTEM); - attributes.add(SemanticAttributes.DB_OPERATION); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(NetworkAttributes.NETWORK_PEER_PORT); - attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); - - ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); - } - - static void applyRecordSizeAdvice(DoubleHistogramBuilder builder) { - if (!(builder instanceof ExtendedDoubleHistogramBuilder)) { - return; - } - - List> attributes = new ArrayList<>(); - attributes.add(SemanticAttributes.DB_SYSTEM); - attributes.add(SemanticAttributes.DB_OPERATION); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE); - attributes.add(AerospikeSemanticAttributes.AEROSPIKE_STATUS); - attributes.add(SemanticAttributes.NETWORK_TYPE); - attributes.add(NetworkAttributes.NETWORK_PEER_PORT); - attributes.add(NetworkAttributes.NETWORK_PEER_ADDRESS); + attributes.add(DB_SYSTEM); + attributes.add(DB_OPERATION); + attributes.add(DB_NAME); + attributes.add(AEROSPIKE_SET_NAME); + attributes.add(AEROSPIKE_STATUS); + attributes.add(NETWORK_PEER_ADDRESS); + attributes.add(NETWORK_PEER_PORT); + attributes.add(NETWORK_TYPE); + attributes.add(AEROSPIKE_NODE_NAME); ((ExtendedDoubleHistogramBuilder) builder).setAttributesAdvice(attributes); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java index 9469eac55fbd..ce780342c676 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java @@ -9,6 +9,12 @@ import static io.opentelemetry.api.common.AttributeKey.stringKey; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; +import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT; +import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_NAME; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_OPERATION; +import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM; import static java.util.Collections.singletonList; import com.aerospike.client.AerospikeClient; @@ -20,10 +26,8 @@ import com.aerospike.client.policy.ClientPolicy; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.instrumentation.api.semconv.network.internal.NetworkAttributes; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; -import io.opentelemetry.semconv.SemanticAttributes; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import org.junit.jupiter.api.AfterAll; @@ -34,17 +38,14 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; +@SuppressWarnings("deprecation") // using deprecated semconv class AerospikeClientTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); - public static final AttributeKey AEROSPIKE_STATUS = stringKey("aerospike.status"); - public static final AttributeKey AEROSPIKE_ERROR_CODE = longKey("aerospike.error.code"); - public static final AttributeKey AEROSPIKE_NAMESPACE = stringKey("aerospike.namespace"); - public static final AttributeKey AEROSPIKE_SET_NAME = stringKey("aerospike.set.name"); - public static final AttributeKey AEROSPIKE_USER_KEY = stringKey("aerospike.user.key"); - public static final AttributeKey AEROSPIKE_TRANSFER_SIZE = - longKey("aerospike.transfer.size"); + public static final AttributeKey AEROSPIKE_STATUS = longKey("db.status"); + public static final AttributeKey AEROSPIKE_SET_NAME = stringKey("db.set.name"); + public static final AttributeKey AEROSPIKE_NODE_NAME = stringKey("db.node.name"); static GenericContainer aerospikeServer = new GenericContainer<>("aerospike/aerospike-server:6.2.0.0") @@ -58,7 +59,7 @@ class AerospikeClientTest { @BeforeAll static void setupSpec() { aerospikeServer.start(); - port = aerospikeServer.getMappedPort(3000); + port = 3000; ClientPolicy clientPolicy = new ClientPolicy(); int eventLoopSize = Runtime.getRuntime().availableProcessors(); System.out.println(eventLoopSize); @@ -67,7 +68,7 @@ static void setupSpec() { clientPolicy.eventLoops = new NioEventLoops(eventPolicy, eventLoopSize); clientPolicy.maxConnsPerNode = eventLoopSize; clientPolicy.failIfNotConnected = true; - aerospikeClient = new AerospikeClient(clientPolicy, "localhost", port); + aerospikeClient = new AerospikeClient(clientPolicy, "localhost", 3000); } @AfterAll @@ -92,71 +93,20 @@ void asyncCommand() { instrumentationName.set(trace.getSpan(0).getInstrumentationScopeInfo().getName()); trace.hasSpansSatisfyingExactly( span -> - span.hasName("ASYNCWRITE") + span.hasName("PUT test") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), - equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), - equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), - equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_SYSTEM, "aerospike"), + equalTo(DB_OPERATION, "PUT"), + equalTo(NETWORK_PEER_PORT, port), + equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NETWORK_TYPE, "ipv4"), + equalTo(DB_NAME, "test"), + equalTo(AEROSPIKE_NODE_NAME, "BB9040017AC4202"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data1"), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AEROSPIKE_ERROR_CODE, 0))); + equalTo(AEROSPIKE_STATUS, 0))); }); - testing.waitAndAssertMetrics( - instrumentationName.get(), - "aerospike.requests", - metrics -> - metrics.anySatisfy( - metric -> - assertThat(metric) - .hasLongSumSatisfying( - counter -> - counter.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data1"), - equalTo( - SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), - equalTo( - SemanticAttributes.DB_SYSTEM, "aerospike")))))); - testing.waitAndAssertMetrics( - instrumentationName.get(), - "aerospike.response", - metrics -> - metrics.anySatisfy( - metric -> - assertThat(metric) - .hasName("aerospike.response") - .hasLongSumSatisfying( - counter -> - counter.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data1"), - equalTo( - SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo( - NetworkAttributes.NETWORK_PEER_ADDRESS, - "127.0.0.1"), - equalTo( - SemanticAttributes.NETWORK_TYPE, "ipv4")))))); - testing.waitAndAssertMetrics( instrumentationName.get(), "aerospike.concurrency", @@ -171,13 +121,10 @@ void asyncCommand() { point .hasValue(0) .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_NAME, "test"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data1"), - equalTo( - SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), - equalTo( - SemanticAttributes.DB_SYSTEM, "aerospike")))))); + equalTo(DB_OPERATION, "PUT"), + equalTo(DB_SYSTEM, "aerospike")))))); testing.waitAndAssertMetrics( instrumentationName.get(), @@ -192,17 +139,15 @@ void asyncCommand() { histogram.hasPointsSatisfying( point -> point.hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_NAME, "test"), + equalTo(AEROSPIKE_NODE_NAME, "BB9040017AC4202"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data1"), - equalTo(SemanticAttributes.DB_OPERATION, "ASYNCWRITE"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo( - NetworkAttributes.NETWORK_PEER_ADDRESS, - "127.0.0.1"), - equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")))))); + equalTo(DB_OPERATION, "PUT"), + equalTo(DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_STATUS, 0), + equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NETWORK_PEER_PORT, 3000), + equalTo(NETWORK_TYPE, "ipv4")))))); } @Test @@ -220,113 +165,37 @@ void syncCommand() { instrumentationName.set(trace.getSpan(0).getInstrumentationScopeInfo().getName()); trace.hasSpansSatisfyingExactly( span -> - span.hasName("PUT") + span.hasName("PUT test") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "PUT"), - equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), - equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), - equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_SYSTEM, "aerospike"), + equalTo(DB_OPERATION, "PUT"), + equalTo(DB_NAME, "test"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AEROSPIKE_ERROR_CODE, 0))); + equalTo(AEROSPIKE_STATUS, 0), + equalTo(AEROSPIKE_NODE_NAME, "BB9040017AC4202"), + equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NETWORK_PEER_PORT, 3000), + equalTo(NETWORK_TYPE, "ipv4"))); }, trace -> { instrumentationName.set(trace.getSpan(0).getInstrumentationScopeInfo().getName()); trace.hasSpansSatisfyingExactly( span -> - span.hasName("GET") + span.hasName("GET test") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(NetworkAttributes.NETWORK_PEER_PORT, port), - equalTo(NetworkAttributes.NETWORK_PEER_ADDRESS, "127.0.0.1"), - equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4"), - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_SYSTEM, "aerospike"), + equalTo(DB_OPERATION, "GET"), + equalTo(DB_NAME, "test"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_TRANSFER_SIZE, 6))); + equalTo(AEROSPIKE_STATUS, 0), + equalTo(AEROSPIKE_NODE_NAME, "BB9040017AC4202"), + equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NETWORK_PEER_PORT, 3000), + equalTo(NETWORK_TYPE, "ipv4"))); }); - testing.waitAndAssertMetrics( - instrumentationName.get(), - "aerospike.requests", - metrics -> - metrics.anySatisfy( - metric -> - assertThat(metric) - .hasLongSumSatisfying( - counter -> - counter.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "PUT"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")), - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo( - SemanticAttributes.DB_SYSTEM, "aerospike")))))); - - testing.waitAndAssertMetrics( - instrumentationName.get(), - "aerospike.response", - metrics -> - metrics.anySatisfy( - metric -> - assertThat(metric) - .hasName("aerospike.response") - .hasLongSumSatisfying( - counter -> - counter.hasPointsSatisfying( - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "PUT"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo( - NetworkAttributes.NETWORK_PEER_ADDRESS, - "127.0.0.1"), - equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")), - point -> - point - .hasValue(1) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo( - NetworkAttributes.NETWORK_PEER_ADDRESS, - "127.0.0.1"), - equalTo( - SemanticAttributes.NETWORK_TYPE, "ipv4")))))); - testing.waitAndAssertMetrics( instrumentationName.get(), "aerospike.concurrency", @@ -341,21 +210,18 @@ void syncCommand() { point .hasValue(0) .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_NAME, "test"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "PUT"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike")), + equalTo(DB_OPERATION, "PUT"), + equalTo(DB_SYSTEM, "aerospike")), point -> point .hasValue(0) .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_NAME, "test"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo( - SemanticAttributes.DB_SYSTEM, "aerospike")))))); + equalTo(DB_OPERATION, "GET"), + equalTo(DB_SYSTEM, "aerospike")))))); testing.waitAndAssertMetrics( instrumentationName.get(), @@ -370,57 +236,25 @@ void syncCommand() { histogram.hasPointsSatisfying( point -> point.hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_SYSTEM, "aerospike"), + equalTo(DB_NAME, "test"), + equalTo(DB_OPERATION, "PUT"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "PUT"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo( - NetworkAttributes.NETWORK_PEER_ADDRESS, - "127.0.0.1"), - equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")), + equalTo(AEROSPIKE_STATUS, 0), + equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NETWORK_PEER_PORT, 3000), + equalTo(NETWORK_TYPE, "ipv4"), + equalTo(AEROSPIKE_NODE_NAME, "BB9040017AC4202")), point -> point.hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), + equalTo(DB_NAME, "test"), equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo( - NetworkAttributes.NETWORK_PEER_ADDRESS, - "127.0.0.1"), - equalTo(SemanticAttributes.NETWORK_TYPE, "ipv4")))))); - - testing.waitAndAssertMetrics( - instrumentationName.get(), - "aerospike.record.size", - metrics -> - metrics.anySatisfy( - metric -> - assertThat(metric) - .hasUnit("By") - .hasHistogramSatisfying( - histogram -> - histogram.hasPointsSatisfying( - point -> - point - .hasSum(6) - .hasAttributesSatisfying( - equalTo(AEROSPIKE_NAMESPACE, "test"), - equalTo(AEROSPIKE_SET_NAME, "test-set"), - equalTo(AEROSPIKE_USER_KEY, "data2"), - equalTo(SemanticAttributes.DB_OPERATION, "GET"), - equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"), - equalTo(AEROSPIKE_ERROR_CODE, 0), - equalTo(AEROSPIKE_STATUS, "SUCCESS"), - equalTo( - NetworkAttributes.NETWORK_PEER_ADDRESS, - "127.0.0.1"), - equalTo( - SemanticAttributes.NETWORK_TYPE, "ipv4")))))); + equalTo(DB_OPERATION, "GET"), + equalTo(DB_SYSTEM, "aerospike"), + equalTo(AEROSPIKE_STATUS, 0), + equalTo(NETWORK_PEER_ADDRESS, "127.0.0.1"), + equalTo(NETWORK_PEER_PORT, 3000), + equalTo(NETWORK_TYPE, "ipv4"), + equalTo(AEROSPIKE_NODE_NAME, "BB9040017AC4202")))))); } } From 453c2b9bdf30569679be23d7cee37fd0168452f6 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 26 Nov 2024 20:33:00 +0530 Subject: [PATCH 17/21] fixes errors --- .../.kotlin/errors/errors-1732624750398.log | 4 +++ .../javaagent/build.gradle.kts | 4 +-- ...va => AerospikeClientInstrumentation.java} | 36 +++++++++---------- .../AerospikeClientInstrumentationModule.java | 9 +++-- .../v7_0/AsyncCommandInstrumentation.java | 4 +-- .../v7_0/internal/CustomElementMatcher.java | 4 --- .../aerospike/v7_0/AerospikeClientTest.java | 1 - 7 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 conventions/.kotlin/errors/errors-1732624750398.log rename instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/{IAerospikeClientInstrumentation.java => AerospikeClientInstrumentation.java} (78%) diff --git a/conventions/.kotlin/errors/errors-1732624750398.log b/conventions/.kotlin/errors/errors-1732624750398.log new file mode 100644 index 000000000000..7cd151b6c7de --- /dev/null +++ b/conventions/.kotlin/errors/errors-1732624750398.log @@ -0,0 +1,4 @@ +kotlin version: 2.0.20 +error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output: + 1. Kotlin compile daemon is ready + diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts index f25c6fcc9fc0..6a472ed6aac1 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts @@ -6,13 +6,13 @@ muzzle { pass { group.set("com.aerospike") module.set("aerospike-client") - versions.set("[7.0.0,)") + versions.set("[4.0.0,)") assertInverse.set(true) } } dependencies { - implementation("com.aerospike:aerospike-client:7.0.0") + library("com.aerospike:aerospike-client:8.0.0") implementation("io.opentelemetry:opentelemetry-api-incubator") compileOnly("com.google.auto.value:auto-value-annotations") diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/IAerospikeClientInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java similarity index 78% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/IAerospikeClientInstrumentation.java rename to instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java index 7712c1405852..8a93e9bd753b 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/IAerospikeClientInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java @@ -7,7 +7,6 @@ import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.CustomElementMatcher.argumentOfType; import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.CustomElementMatcher.iterableHasAtLeastOne; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.isMethod; @@ -15,9 +14,7 @@ import static net.bytebuddy.matcher.ElementMatchers.not; import static net.bytebuddy.matcher.ElementMatchers.takesGenericArguments; -import com.aerospike.client.AerospikeException; import com.aerospike.client.Key; -import com.aerospike.client.async.EventLoop; import io.opentelemetry.context.Context; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; @@ -28,7 +25,8 @@ import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; -public class IAerospikeClientInstrumentation implements TypeInstrumentation { +public class AerospikeClientInstrumentation implements TypeInstrumentation { + @Override public ElementMatcher typeMatcher() { return hasSuperType(named("com.aerospike.client.IAerospikeClient")); @@ -38,22 +36,22 @@ public ElementMatcher typeMatcher() { public void transform(TypeTransformer transformer) { transformer.applyAdviceToMethod( isMethod() - .and(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(Key.class)))) + .and(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.Key")))) .and( - not(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(EventLoop.class))))), + not(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.async.EventLoop"))))), this.getClass().getName() + "$SyncCommandAdvice"); transformer.applyAdviceToMethod( isMethod() - .and(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(Key.class)))) - .and(takesGenericArguments(iterableHasAtLeastOne(argumentOfType(EventLoop.class)))), + .and(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.Key")))) + .and(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.async.EventLoop")))), this.getClass().getName() + "$AsyncCommandAdvice"); } @SuppressWarnings("unused") public static class SyncCommandAdvice { - @Advice.OnMethodEnter(suppress = AerospikeException.class) + @Advice.OnMethodEnter(suppress = Throwable.class) public static void startInstrumentation( @Advice.Origin("#m") String methodName, @Advice.AllArguments Object[] args, @@ -78,12 +76,12 @@ public static void startInstrumentation( } @Advice.OnMethodExit( - onThrowable = AerospikeException.class, - suppress = AerospikeException.class) + onThrowable = Throwable.class, + suppress = Throwable.class) public static void stopInstrumentation( - @Advice.Thrown AerospikeException ae, + @Advice.Thrown Throwable ex, @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { - requestContext.setThrowable(ae); + requestContext.setThrowable(ex); requestContext.detachAndEnd(); } } @@ -91,7 +89,7 @@ public static void stopInstrumentation( @SuppressWarnings("unused") public static class AsyncCommandAdvice { - @Advice.OnMethodEnter(suppress = AerospikeException.class) + @Advice.OnMethodEnter(suppress = Throwable.class) public static void startInstrumentation( @Advice.Origin("#m") String methodName, @Advice.AllArguments Object[] args, @@ -116,13 +114,13 @@ public static void startInstrumentation( } @Advice.OnMethodExit( - onThrowable = AerospikeException.class, - suppress = AerospikeException.class) + onThrowable = Throwable.class, + suppress = Throwable.class) public static void stopInstrumentaionIfError( - @Advice.Thrown AerospikeException ae, + @Advice.Thrown Throwable ex, @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { - if (ae != null) { - requestContext.setThrowable(ae); + if (ex != null) { + requestContext.setThrowable(ex); requestContext.detachAndEnd(); } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java index bd2b0caf3e95..ad6ec3a74b03 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java @@ -23,13 +23,18 @@ public AerospikeClientInstrumentationModule() { @Override public ElementMatcher.Junction classLoaderMatcher() { - return hasClassesNamed("com.aerospike.client.IAerospikeClient"); + return hasClassesNamed("com.aerospike.client.IAerospikeClient"). + and(hasClassesNamed("com.aerospike.client.command.Command")). + and(hasClassesNamed("com.aerospike.client.command.SyncCommand")). + and(hasClassesNamed("com.aerospike.client.async.AsyncCommand")). + and(hasClassesNamed("com.aerospike.client.async.EventLoop")). + and(hasClassesNamed("com.aerospike.client.Key")); } @Override public List typeInstrumentations() { return asList( - new IAerospikeClientInstrumentation(), + new AerospikeClientInstrumentation(), new SyncCommandInstrumentation(), new AsyncCommandInstrumentation()); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java index a5e8c4091be8..47d088a036a6 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java @@ -11,7 +11,7 @@ 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.takesGenericArguments; +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import com.aerospike.client.AerospikeException; import com.aerospike.client.cluster.Node; @@ -48,7 +48,7 @@ public void transform(TypeTransformer transformer) { isMethod().and(named("onSuccess")), this.getClass().getName() + "$GetOnSuccessAdvice"); transformer.applyAdviceToMethod( - isMethod().and(named("onFailure").and(takesGenericArguments(AerospikeException.class))), + isMethod().and(named("onFailure").and(takesArgument(0, named("com.aerospike.client.AerospikeException")))), this.getClass().getName() + "$GetOnFailureAdvice"); } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java index 628d871e9837..549364d8759e 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java @@ -26,8 +26,4 @@ public static ElementMatcher> iterab return false; }; } - - public static ElementMatcher argumentOfType(Class clazz) { - return typeDescription -> typeDescription.asErasure().represents(clazz); - } } diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java index ce780342c676..f5c29b4e11e4 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java @@ -62,7 +62,6 @@ static void setupSpec() { port = 3000; ClientPolicy clientPolicy = new ClientPolicy(); int eventLoopSize = Runtime.getRuntime().availableProcessors(); - System.out.println(eventLoopSize); EventPolicy eventPolicy = new EventPolicy(); eventPolicy.commandsPerEventLoop = 2; clientPolicy.eventLoops = new NioEventLoops(eventPolicy, eventLoopSize); From 3b6ab9b900e816a25f410c1dc3d05ec3655c76bd Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 26 Nov 2024 21:12:15 +0530 Subject: [PATCH 18/21] applies spotless fixes --- .../v7_0/AerospikeClientInstrumentation.java | 16 ++++++++-------- .../AerospikeClientInstrumentationModule.java | 12 ++++++------ .../v7_0/AsyncCommandInstrumentation.java | 5 ++++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java index 8a93e9bd753b..110af44af01f 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java @@ -38,13 +38,17 @@ public void transform(TypeTransformer transformer) { isMethod() .and(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.Key")))) .and( - not(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.async.EventLoop"))))), + not( + takesGenericArguments( + iterableHasAtLeastOne(named("com.aerospike.client.async.EventLoop"))))), this.getClass().getName() + "$SyncCommandAdvice"); transformer.applyAdviceToMethod( isMethod() .and(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.Key")))) - .and(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.async.EventLoop")))), + .and( + takesGenericArguments( + iterableHasAtLeastOne(named("com.aerospike.client.async.EventLoop")))), this.getClass().getName() + "$AsyncCommandAdvice"); } @@ -75,9 +79,7 @@ public static void startInstrumentation( requestContext = AerospikeRequestContext.attach(request, context); } - @Advice.OnMethodExit( - onThrowable = Throwable.class, - suppress = Throwable.class) + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopInstrumentation( @Advice.Thrown Throwable ex, @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { @@ -113,9 +115,7 @@ public static void startInstrumentation( requestContext = AerospikeRequestContext.attach(request, context); } - @Advice.OnMethodExit( - onThrowable = Throwable.class, - suppress = Throwable.class) + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void stopInstrumentaionIfError( @Advice.Thrown Throwable ex, @Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java index ad6ec3a74b03..ad593c2a7cd8 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java @@ -23,12 +23,12 @@ public AerospikeClientInstrumentationModule() { @Override public ElementMatcher.Junction classLoaderMatcher() { - return hasClassesNamed("com.aerospike.client.IAerospikeClient"). - and(hasClassesNamed("com.aerospike.client.command.Command")). - and(hasClassesNamed("com.aerospike.client.command.SyncCommand")). - and(hasClassesNamed("com.aerospike.client.async.AsyncCommand")). - and(hasClassesNamed("com.aerospike.client.async.EventLoop")). - and(hasClassesNamed("com.aerospike.client.Key")); + return hasClassesNamed("com.aerospike.client.IAerospikeClient") + .and(hasClassesNamed("com.aerospike.client.command.Command")) + .and(hasClassesNamed("com.aerospike.client.command.SyncCommand")) + .and(hasClassesNamed("com.aerospike.client.async.AsyncCommand")) + .and(hasClassesNamed("com.aerospike.client.async.EventLoop")) + .and(hasClassesNamed("com.aerospike.client.Key")); } @Override diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java index 47d088a036a6..3c2b30ec8bac 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java @@ -48,7 +48,10 @@ public void transform(TypeTransformer transformer) { isMethod().and(named("onSuccess")), this.getClass().getName() + "$GetOnSuccessAdvice"); transformer.applyAdviceToMethod( - isMethod().and(named("onFailure").and(takesArgument(0, named("com.aerospike.client.AerospikeException")))), + isMethod() + .and( + named("onFailure") + .and(takesArgument(0, named("com.aerospike.client.AerospikeException")))), this.getClass().getName() + "$GetOnFailureAdvice"); } From c34b20ddc6caa9de596fb9c96cfb53bfd38cbaab Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 26 Nov 2024 22:14:11 +0530 Subject: [PATCH 19/21] refactoring module a level up --- .../{aerospike-client-7.0 => }/javaagent/build.gradle.kts | 0 .../aerospike/v7_0/AerospikeClientAttributeExtractor.java | 0 .../aerospike/v7_0/AerospikeClientInstrumentation.java | 0 .../aerospike/v7_0/AerospikeClientInstrumentationModule.java | 2 +- .../aerospike/v7_0/AerospikeDbAttributesGetter.java | 0 .../aerospike/v7_0/AerospikeNetworkAttributesGetter.java | 0 .../instrumentation/aerospike/v7_0/AersopikeSingletons.java | 2 +- .../aerospike/v7_0/AsyncCommandInstrumentation.java | 0 .../aerospike/v7_0/SyncCommandInstrumentation.java | 0 .../aerospike/v7_0/internal/AerospikeRequest.java | 0 .../aerospike/v7_0/internal/AerospikeRequestContext.java | 0 .../aerospike/v7_0/internal/AerospikeSemanticAttributes.java | 0 .../aerospike/v7_0/internal/CustomElementMatcher.java | 0 .../aerospike/v7_0/metrics/AerospikeMetrics.java | 0 .../aerospike/v7_0/metrics/AerospikeMetricsAdvice.java | 0 .../instrumentation/aerospike/v7_0/AerospikeClientTest.java | 0 settings.gradle.kts | 2 +- 17 files changed, 3 insertions(+), 3 deletions(-) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/build.gradle.kts (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java (96%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java (98%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java (100%) rename instrumentation/aerospike-client/{aerospike-client-7.0 => }/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java (100%) diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts b/instrumentation/aerospike-client/javaagent/build.gradle.kts similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/build.gradle.kts rename to instrumentation/aerospike-client/javaagent/build.gradle.kts diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java similarity index 96% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java index ad593c2a7cd8..34d832876cff 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java @@ -18,7 +18,7 @@ public class AerospikeClientInstrumentationModule extends InstrumentationModule { public AerospikeClientInstrumentationModule() { - super("aerospike-client", "aerospike-client-7.0.0"); + super("aerospike-client"); } @Override diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java similarity index 98% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java index ce2b6619f082..6948765cdf96 100644 --- a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java @@ -19,7 +19,7 @@ import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics.AerospikeMetrics; public final class AersopikeSingletons { - private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client-7.0"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client"; private static final Instrumenter INSTRUMENTER; diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java diff --git a/instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java b/instrumentation/aerospike-client/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java similarity index 100% rename from instrumentation/aerospike-client/aerospike-client-7.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java rename to instrumentation/aerospike-client/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientTest.java diff --git a/settings.gradle.kts b/settings.gradle.kts index 7452dd3f15b7..53ae5767c774 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -172,7 +172,7 @@ include(":smoke-tests-otel-starter:spring-boot-reactive-2") include(":smoke-tests-otel-starter:spring-boot-reactive-3") include(":smoke-tests-otel-starter:spring-boot-reactive-common") -include(":instrumentation:aerospike-client:aerospike-client-7.0:javaagent") +include(":instrumentation:aerospike-client:javaagent") include(":instrumentation:akka:akka-actor-2.3:javaagent") include(":instrumentation:akka:akka-actor-fork-join-2.5:javaagent") include(":instrumentation:akka:akka-http-10.0:javaagent") From 72c35de7904d094faa46ea5377097434f1aefcf7 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 27 Nov 2024 18:55:23 +0530 Subject: [PATCH 20/21] fixes muzzle, refactors module, updates classLoadMatcher and added doc --- .../.kotlin/errors/errors-1732624750398.log | 4 ---- docs/supported-libraries.md | 1 + instrumentation/aerospike-client/README.md | 2 +- .../aerospike-client/javaagent/build.gradle.kts | 17 +++++++++++++++-- .../AerospikeClientAttributeExtractor.java | 6 +++--- .../AerospikeClientInstrumentation.java | 10 +++++----- .../AerospikeClientInstrumentationModule.java | 9 ++------- .../{v7_0 => }/AerospikeDbAttributesGetter.java | 6 +++--- .../AerospikeNetworkAttributesGetter.java | 4 ++-- ...Singletons.java => AerospikeSingletons.java} | 10 +++++----- .../{v7_0 => }/AsyncCommandInstrumentation.java | 4 ++-- .../{v7_0 => }/SyncCommandInstrumentation.java | 4 ++-- .../{v7_0 => }/internal/AerospikeRequest.java | 2 +- .../internal/AerospikeRequestContext.java | 4 ++-- .../internal/AerospikeSemanticAttributes.java | 2 +- .../internal/CustomElementMatcher.java | 2 +- .../{v7_0 => }/metrics/AerospikeMetrics.java | 2 +- .../metrics/AerospikeMetricsAdvice.java | 8 ++++---- 18 files changed, 51 insertions(+), 46 deletions(-) delete mode 100644 conventions/.kotlin/errors/errors-1732624750398.log rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/AerospikeClientAttributeExtractor.java (86%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/AerospikeClientInstrumentation.java (92%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/AerospikeClientInstrumentationModule.java (68%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/AerospikeDbAttributesGetter.java (78%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/AerospikeNetworkAttributesGetter.java (80%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0/AersopikeSingletons.java => AerospikeSingletons.java} (88%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/AsyncCommandInstrumentation.java (96%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/SyncCommandInstrumentation.java (91%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/internal/AerospikeRequest.java (90%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/internal/AerospikeRequestContext.java (92%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/internal/AerospikeSemanticAttributes.java (93%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/internal/CustomElementMatcher.java (90%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/metrics/AerospikeMetrics.java (97%) rename instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/{v7_0 => }/metrics/AerospikeMetricsAdvice.java (89%) diff --git a/conventions/.kotlin/errors/errors-1732624750398.log b/conventions/.kotlin/errors/errors-1732624750398.log deleted file mode 100644 index 7cd151b6c7de..000000000000 --- a/conventions/.kotlin/errors/errors-1732624750398.log +++ /dev/null @@ -1,4 +0,0 @@ -kotlin version: 2.0.20 -error message: The daemon has terminated unexpectedly on startup attempt #1 with error code: 0. The daemon process output: - 1. Kotlin compile daemon is ready - diff --git a/docs/supported-libraries.md b/docs/supported-libraries.md index 74bea2ded278..c8bbf6aaf554 100644 --- a/docs/supported-libraries.md +++ b/docs/supported-libraries.md @@ -19,6 +19,7 @@ These are the supported libraries and frameworks: | Library/Framework | Auto-instrumented versions | Standalone Library Instrumentation [1] | Semantic Conventions | |---------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------| +| [Aerospike Client](https://github.com/aerospike/aerospike-client-java) | 7.1+ | N/A | [Database Pool Metrics] | | [Akka Actors](https://doc.akka.io/docs/akka/current/typed/index.html) | 2.3+ | N/A | Context propagation | | [Akka HTTP](https://doc.akka.io/docs/akka-http/current/index.html) | 10.0+ | N/A | [HTTP Client Spans], [HTTP Client Metrics], [HTTP Server Spans], [HTTP Server Metrics], Provides `http.route` [2] | | [Alibaba Druid](https://github.com/alibaba/druid) | 1.0+ | [opentelemetry-alibaba-druid-1.0](../instrumentation/alibaba-druid-1.0/library) | [Database Pool Metrics] | diff --git a/instrumentation/aerospike-client/README.md b/instrumentation/aerospike-client/README.md index 35a6e816e959..fbaefe6207c7 100644 --- a/instrumentation/aerospike-client/README.md +++ b/instrumentation/aerospike-client/README.md @@ -3,4 +3,4 @@ | System property | Type | Default | Description | |---------------------------------------------------------------|---------|---------|----------------------------------------------------------------------| | `otel.instrumentation.aerospike.experimental-span-attributes` | Boolean | `false` | Enable the capture of experimental Aerospike client span attributes. | -| `otel.instrumentation.aerospike.experimental-metrics` | Boolean | `false` | Enable the recording of experimental Aerospike client metrics | +| `otel.instrumentation.aerospike.experimental-metrics` | Boolean | `false` | Enable the recording of experimental Aerospike client metrics. | diff --git a/instrumentation/aerospike-client/javaagent/build.gradle.kts b/instrumentation/aerospike-client/javaagent/build.gradle.kts index 6a472ed6aac1..34c87a655309 100644 --- a/instrumentation/aerospike-client/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/javaagent/build.gradle.kts @@ -6,19 +6,32 @@ muzzle { pass { group.set("com.aerospike") module.set("aerospike-client") - versions.set("[4.0.0,)") + versions.set("[7.1.0,)") assertInverse.set(true) } } +val latestDepTest = findProperty("testLatestDeps") as Boolean + dependencies { - library("com.aerospike:aerospike-client:8.0.0") + if (latestDepTest) { + library("com.aerospike:aerospike-client:+") + } else { + library("com.aerospike:aerospike-client:7.1.0") + } + implementation("io.opentelemetry:opentelemetry-api-incubator") compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") } +if (latestDepTest) { + otelJava { + minJavaVersionSupported.set(JavaVersion.VERSION_21) + } +} + tasks { test { jvmArgs("-Djava.net.preferIPv4Stack=true") diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientAttributeExtractor.java similarity index 86% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientAttributeExtractor.java index afcadac1599c..56f97060dd43 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientAttributeExtractor.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientAttributeExtractor.java @@ -3,15 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import com.aerospike.client.AerospikeException; import com.aerospike.client.ResultCode; import io.opentelemetry.api.common.AttributesBuilder; import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeSemanticAttributes; import javax.annotation.Nullable; final class AerospikeClientAttributeExtractor diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentation.java similarity index 92% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentation.java index 110af44af01f..89841655f5bb 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentation.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentation.java @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.CustomElementMatcher.iterableHasAtLeastOne; +import static io.opentelemetry.javaagent.instrumentation.aerospike.AerospikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike.internal.CustomElementMatcher.iterableHasAtLeastOne; import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.named; @@ -18,8 +18,8 @@ import io.opentelemetry.context.Context; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequestContext; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequestContext; import java.util.Locale; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentationModule.java similarity index 68% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentationModule.java index 34d832876cff..038d8ddb170c 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeClientInstrumentationModule.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentationModule.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static java.util.Arrays.asList; @@ -23,12 +23,7 @@ public AerospikeClientInstrumentationModule() { @Override public ElementMatcher.Junction classLoaderMatcher() { - return hasClassesNamed("com.aerospike.client.IAerospikeClient") - .and(hasClassesNamed("com.aerospike.client.command.Command")) - .and(hasClassesNamed("com.aerospike.client.command.SyncCommand")) - .and(hasClassesNamed("com.aerospike.client.async.AsyncCommand")) - .and(hasClassesNamed("com.aerospike.client.async.EventLoop")) - .and(hasClassesNamed("com.aerospike.client.Key")); + return hasClassesNamed("com.aerospike.client.metrics.LatencyType"); } @Override diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeDbAttributesGetter.java similarity index 78% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeDbAttributesGetter.java index 4de76bdeae70..a59047c4d775 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeDbAttributesGetter.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeDbAttributesGetter.java @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeSemanticAttributes; import javax.annotation.Nullable; final class AerospikeDbAttributesGetter implements DbClientAttributesGetter { diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeNetworkAttributesGetter.java similarity index 80% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeNetworkAttributesGetter.java index affb07b68a9b..2cc53fbb46f8 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AerospikeNetworkAttributesGetter.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeNetworkAttributesGetter.java @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import com.aerospike.client.cluster.Node; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequest; import java.net.InetSocketAddress; import javax.annotation.Nullable; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeSingletons.java similarity index 88% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeSingletons.java index 6948765cdf96..9672a4802e92 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AersopikeSingletons.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeSingletons.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.instrumentation.api.incubator.config.internal.InstrumentationConfig; @@ -15,10 +15,10 @@ import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesExtractor; import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequest; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics.AerospikeMetrics; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequest; +import io.opentelemetry.javaagent.instrumentation.aerospike.metrics.AerospikeMetrics; -public final class AersopikeSingletons { +public final class AerospikeSingletons { private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client"; private static final Instrumenter INSTRUMENTER; @@ -52,5 +52,5 @@ public static Instrumenter instrumenter() { return INSTRUMENTER; } - private AersopikeSingletons() {} + private AerospikeSingletons() {} } diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AsyncCommandInstrumentation.java similarity index 96% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AsyncCommandInstrumentation.java index 3c2b30ec8bac..0206635a2981 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/AsyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/AsyncCommandInstrumentation.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; @@ -19,7 +19,7 @@ import io.opentelemetry.instrumentation.api.util.VirtualField; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequestContext; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequestContext; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/SyncCommandInstrumentation.java similarity index 91% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/SyncCommandInstrumentation.java index af9e0ef0b669..86b6332b8c62 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/SyncCommandInstrumentation.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/SyncCommandInstrumentation.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; +package io.opentelemetry.javaagent.instrumentation.aerospike; import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass; @@ -13,7 +13,7 @@ import com.aerospike.client.cluster.Node; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; -import io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeRequestContext; +import io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeRequestContext; import net.bytebuddy.asm.Advice; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeRequest.java similarity index 90% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeRequest.java index 47cc7d84fc61..909e563075e6 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequest.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeRequest.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; +package io.opentelemetry.javaagent.instrumentation.aerospike.internal; import com.aerospike.client.cluster.Node; import com.google.auto.value.AutoValue; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeRequestContext.java similarity index 92% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeRequestContext.java index f3460e09ef9b..2eb30d2b6a06 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeRequestContext.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeRequestContext.java @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; +package io.opentelemetry.javaagent.instrumentation.aerospike.internal; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.AersopikeSingletons.instrumenter; +import static io.opentelemetry.javaagent.instrumentation.aerospike.AerospikeSingletons.instrumenter; import io.opentelemetry.context.Context; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeSemanticAttributes.java similarity index 93% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeSemanticAttributes.java index 2edd54778674..4cf8170e0dc7 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/AerospikeSemanticAttributes.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/AerospikeSemanticAttributes.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; +package io.opentelemetry.javaagent.instrumentation.aerospike.internal; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/CustomElementMatcher.java similarity index 90% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/CustomElementMatcher.java index 549364d8759e..b3b5881a4e6e 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/internal/CustomElementMatcher.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/internal/CustomElementMatcher.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal; +package io.opentelemetry.javaagent.instrumentation.aerospike.internal; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/metrics/AerospikeMetrics.java similarity index 97% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/metrics/AerospikeMetrics.java index 54f10f3219f2..893e2028ac61 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetrics.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/metrics/AerospikeMetrics.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; +package io.opentelemetry.javaagent.instrumentation.aerospike.metrics; import static java.util.logging.Level.FINE; diff --git a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/metrics/AerospikeMetricsAdvice.java similarity index 89% rename from instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java rename to instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/metrics/AerospikeMetricsAdvice.java index 23eff543d220..eb8a3872b0bc 100644 --- a/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/v7_0/metrics/AerospikeMetricsAdvice.java +++ b/instrumentation/aerospike-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/aerospike/metrics/AerospikeMetricsAdvice.java @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.metrics; +package io.opentelemetry.javaagent.instrumentation.aerospike.metrics; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes.AEROSPIKE_NODE_NAME; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes.AEROSPIKE_SET_NAME; -import static io.opentelemetry.javaagent.instrumentation.aerospike.v7_0.internal.AerospikeSemanticAttributes.AEROSPIKE_STATUS; +import static io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeSemanticAttributes.AEROSPIKE_NODE_NAME; +import static io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeSemanticAttributes.AEROSPIKE_SET_NAME; +import static io.opentelemetry.javaagent.instrumentation.aerospike.internal.AerospikeSemanticAttributes.AEROSPIKE_STATUS; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_ADDRESS; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_PEER_PORT; import static io.opentelemetry.semconv.NetworkAttributes.NETWORK_TYPE; From 79765c53c5afba5346d3053a41c393ddf4fed97f Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 27 Nov 2024 19:32:44 +0530 Subject: [PATCH 21/21] removes library version check --- .../aerospike-client/javaagent/build.gradle.kts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/instrumentation/aerospike-client/javaagent/build.gradle.kts b/instrumentation/aerospike-client/javaagent/build.gradle.kts index 34c87a655309..f51cf81f2c20 100644 --- a/instrumentation/aerospike-client/javaagent/build.gradle.kts +++ b/instrumentation/aerospike-client/javaagent/build.gradle.kts @@ -14,12 +14,7 @@ muzzle { val latestDepTest = findProperty("testLatestDeps") as Boolean dependencies { - if (latestDepTest) { - library("com.aerospike:aerospike-client:+") - } else { - library("com.aerospike:aerospike-client:7.1.0") - } - + library("com.aerospike:aerospike-client:7.1.0") implementation("io.opentelemetry:opentelemetry-api-incubator") compileOnly("com.google.auto.value:auto-value-annotations")