-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aerospike client instrumentation #9836
base: main
Are you sure you want to change the base?
Changes from 15 commits
faf4a92
a03903c
ecdd747
226b9e1
58f1b46
ec950dc
14f1109
4133b58
b4af69a
d1818c1
e82bdcb
7c17dfc
5da5b5b
5059c8e
93da28f
a30b6d7
7f84218
afda86d
0ef5f40
3a3e509
7d2f3a5
cc92b86
453c2b9
cfc0227
3b6ab9b
c34b20d
72c35de
79765c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("com.aerospike") | ||
module.set("aerospike-client") | ||
versions.set("[4.4.9,)") | ||
assertInverse.set(true) | ||
} | ||
} | ||
|
||
dependencies { | ||
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") | ||
} | ||
|
||
tasks { | ||
test { | ||
jvmArgs("-Djava.net.preferIPv4Stack=true") | ||
jvmArgs("-Dotel.instrumentation.aerospike.experimental-span-attributes=true") | ||
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.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 javax.annotation.Nullable; | ||
|
||
final class AerospikeClientAttributeExtractor | ||
implements AttributesExtractor<AerospikeRequest, Void> { | ||
|
||
@Override | ||
public void onStart( | ||
AttributesBuilder attributes, Context parentContext, AerospikeRequest aerospikeRequest) { | ||
attributes.put( | ||
AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, aerospikeRequest.getNamespace()); | ||
laurit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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()); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.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<ClassLoader> classLoaderMatcher() { | ||
return hasClassesNamed("com.aerospike.client.AerospikeClient"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return asList( | ||
new SyncCommandInstrumentation(), | ||
new SocketInstrumentation(), | ||
new AsyncCommandInstrumentation(), | ||
new AsyncHandlerInstrumentation(), | ||
new AsyncScanAllCommandInstrumentation()); | ||
} | ||
|
||
@Override | ||
public boolean isIndyModule() { | ||
return false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; | ||
|
||
import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; | ||
import javax.annotation.Nullable; | ||
|
||
final class AerospikeDbAttributesGetter implements DbClientAttributesGetter<AerospikeRequest> { | ||
|
||
@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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; | ||
|
||
import com.aerospike.client.cluster.Node; | ||
import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; | ||
import java.net.InetSocketAddress; | ||
import javax.annotation.Nullable; | ||
|
||
final class AerospikeNetworkAttributesGetter | ||
implements NetworkAttributesGetter<AerospikeRequest, Void> { | ||
|
||
@Override | ||
@Nullable | ||
public InetSocketAddress getNetworkPeerInetSocketAddress( | ||
AerospikeRequest aerospikeRequest, @Nullable Void unused) { | ||
Node node = aerospikeRequest.getNode(); | ||
if (node != null) { | ||
return node.getAddress(); | ||
} | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
|
||
public final class AerospikeRequestContext { | ||
private static final ThreadLocal<AerospikeRequestContext> 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the suppress warnings really necessary? |
||
public static AerospikeRequestContext current() { | ||
return contextThreadLocal.get(); | ||
} | ||
|
||
public void endSpan( | ||
Instrumenter<AerospikeRequest, Void> instrumenter, | ||
Context context, | ||
AerospikeRequest request, | ||
Throwable throwable) { | ||
instrumenter.end(context, request, null, throwable); | ||
} | ||
|
||
public AerospikeRequest getRequest() { | ||
return request; | ||
} | ||
|
||
public Context getContext() { | ||
return context; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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 io.opentelemetry.api.common.AttributeKey; | ||
|
||
public final class AerospikeSemanticAttributes { | ||
private AerospikeSemanticAttributes() {} | ||
|
||
public static final AttributeKey<String> AEROSPIKE_STATUS = stringKey("aerospike.status"); | ||
public static final AttributeKey<Long> AEROSPIKE_ERROR_CODE = longKey("aerospike.error.code"); | ||
public static final AttributeKey<String> AEROSPIKE_NAMESPACE = stringKey("aerospike.namespace"); | ||
public static final AttributeKey<String> AEROSPIKE_SET_NAME = stringKey("aerospike.set.name"); | ||
public static final AttributeKey<String> AEROSPIKE_USER_KEY = stringKey("aerospike.user.key"); | ||
public static final AttributeKey<Long> AEROSPIKE_TRANSFER_SIZE = | ||
longKey("aerospike.transfer.size"); | ||
|
||
public static final class DbSystemValues { | ||
public static final String AEROSPIKE = "aerospike"; | ||
|
||
private DbSystemValues() {} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.v7_1; | ||
|
||
import io.opentelemetry.api.GlobalOpenTelemetry; | ||
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.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"; | ||
|
||
private static final Instrumenter<AerospikeRequest, Void> INSTRUMENTER; | ||
|
||
static { | ||
AerospikeDbAttributesGetter aerospikeDbAttributesGetter = new AerospikeDbAttributesGetter(); | ||
NetworkAttributesGetter<AerospikeRequest, Void> netAttributesGetter = | ||
new AerospikeNetworkAttributesGetter(); | ||
|
||
InstrumenterBuilder<AerospikeRequest, Void> builder = | ||
Instrumenter.<AerospikeRequest, Void>builder( | ||
GlobalOpenTelemetry.get(), | ||
INSTRUMENTATION_NAME, | ||
DbClientSpanNameExtractor.create(aerospikeDbAttributesGetter)) | ||
.addAttributesExtractor(DbClientAttributesExtractor.create(aerospikeDbAttributesGetter)) | ||
.addAttributesExtractor(NetworkAttributesExtractor.create(netAttributesGetter)) | ||
.addOperationMetrics(AerospikeMetrics.get()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similarly to experimental span attributes experimental metrics should be behind |
||
if (InstrumentationConfig.get() | ||
.getBoolean("otel.instrumentation.aerospike.experimental-span-attributes", false)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this flag should be document in |
||
builder.addAttributesExtractor(new AerospikeClientAttributeExtractor()); | ||
} | ||
|
||
INSTRUMENTER = builder.buildInstrumenter(SpanKindExtractor.alwaysClient()); | ||
} | ||
|
||
public static Instrumenter<AerospikeRequest, Void> instrumenter() { | ||
return INSTRUMENTER; | ||
} | ||
|
||
private AersopikeSingletons() {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you want this instrumentation to work starting from
7.1.0
and don't care about earlier versions? The idea here is to have the muzzle version the same as the earliest supported version to avoid the situation where instrumentation applies to some earlier version but does not work correctly. You could bring the minimum version down to5.0.0
where tests seem to pass with a small modification or I guess you could artificially restrict the version where the instrumentation works with something likeopentelemetry-java-instrumentation/instrumentation/jedis/jedis-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jedis/v4_0/JedisInstrumentationModule.java
Lines 24 to 27 in 0337158
7.1.0
is present (of course this only works when such a class exists).