-
Notifications
You must be signed in to change notification settings - Fork 917
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 26 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,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 | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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 | | ||||||
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.
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||
plugins { | ||||||||||||
id("otel.javaagent-instrumentation") | ||||||||||||
} | ||||||||||||
|
||||||||||||
muzzle { | ||||||||||||
pass { | ||||||||||||
group.set("com.aerospike") | ||||||||||||
module.set("aerospike-client") | ||||||||||||
versions.set("[4.0.0,)") | ||||||||||||
assertInverse.set(true) | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
dependencies { | ||||||||||||
library("com.aerospike:aerospike-client:8.0.0") | ||||||||||||
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. What version do you want to support? Here you use 8, but in package name you use 7. Muzzle passes for 4, would that work? Lines 83 to 87 in c6a6fa6
|
||||||||||||
implementation("io.opentelemetry:opentelemetry-api-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") | ||||||||||||
jvmArgs("-Dotel.instrumentation.aerospike.experimental-metrics=true") | ||||||||||||
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) | ||||||||||||
} | ||||||||||||
} |
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_0; | ||
|
||
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 javax.annotation.Nullable; | ||
|
||
final class AerospikeClientAttributeExtractor | ||
implements AttributesExtractor<AerospikeRequest, Void> { | ||
|
||
@Override | ||
public void onStart( | ||
AttributesBuilder attributes, Context parentContext, AerospikeRequest aerospikeRequest) { | ||
attributes.put(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, aerospikeRequest.getSet()); | ||
} | ||
|
||
@Override | ||
public void onEnd( | ||
AttributesBuilder attributes, | ||
Context context, | ||
AerospikeRequest aerospikeRequest, | ||
@Nullable Void unused, | ||
@Nullable Throwable error) { | ||
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_STATUS, aerospikeException.getResultCode()); | ||
} else { | ||
attributes.put(AerospikeSemanticAttributes.AEROSPIKE_STATUS, ResultCode.CLIENT_ERROR); | ||
} | ||
} else { | ||
attributes.put(AerospikeSemanticAttributes.AEROSPIKE_STATUS, ResultCode.OK); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* 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.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.Key; | ||
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 AerospikeClientInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return hasSuperType(named("com.aerospike.client.IAerospikeClient")); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isMethod() | ||
.and(takesGenericArguments(iterableHasAtLeastOne(named("com.aerospike.client.Key")))) | ||
.and( | ||
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")))), | ||
this.getClass().getName() + "$AsyncCommandAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class SyncCommandAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.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 = Throwable.class, suppress = Throwable.class) | ||
public static void stopInstrumentation( | ||
@Advice.Thrown Throwable ex, | ||
@Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { | ||
requestContext.setThrowable(ex); | ||
requestContext.detachAndEnd(); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class AsyncCommandAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.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 = Throwable.class, suppress = Throwable.class) | ||
public static void stopInstrumentaionIfError( | ||
@Advice.Thrown Throwable ex, | ||
@Advice.Local("AerospikeContext") AerospikeRequestContext requestContext) { | ||
if (ex != null) { | ||
requestContext.setThrowable(ex); | ||
requestContext.detachAndEnd(); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 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"); | ||
} | ||
|
||
@Override | ||
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
return hasClassesNamed("com.aerospike.client.IAerospikeClient") | ||
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.
|
||
.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<TypeInstrumentation> typeInstrumentations() { | ||
return asList( | ||
new AerospikeClientInstrumentation(), | ||
new SyncCommandInstrumentation(), | ||
new AsyncCommandInstrumentation()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
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<AerospikeRequest> { | ||
|
||
@Override | ||
public String getDbSystem(AerospikeRequest request) { | ||
return AerospikeSemanticAttributes.DbSystemValues.AEROSPIKE; | ||
} | ||
|
||
@Override | ||
public String getDbOperationName(AerospikeRequest request) { | ||
return request.getOperation(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getDbNamespace(AerospikeRequest request) { | ||
return request.getNamespace(); | ||
} | ||
|
||
@Deprecated | ||
@Nullable | ||
@Override | ||
public String getUser(AerospikeRequest aerospikeRequest) { | ||
return null; | ||
} | ||
|
||
@Deprecated | ||
@Nullable | ||
@Override | ||
public String getConnectionString(AerospikeRequest aerospikeRequest) { | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike.v7_0; | ||
|
||
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; | ||
|
||
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,56 @@ | ||||||
/* | ||||||
* Copyright The OpenTelemetry Authors | ||||||
* SPDX-License-Identifier: Apache-2.0 | ||||||
*/ | ||||||
|
||||||
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; | ||||||
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.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 { | ||||||
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.
Suggested change
|
||||||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.aerospike-client"; | ||||||
|
||||||
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)); | ||||||
InstrumentationConfig instrumentationConfig = AgentInstrumentationConfig.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()); | ||||||
} | ||||||
|
||||||
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.
remove this file