-
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
Open
Abhishekkr3003
wants to merge
28
commits into
open-telemetry:main
Choose a base branch
from
Abhishekkr3003:aerospike-client-instrumentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
faf4a92
adds aerospike instrumentation
Abhishekkr3003 a03903c
minor refactoring and adds testInstrumentation
Abhishekkr3003 ecdd747
changes muzzle fail and test case container startup check
Abhishekkr3003 226b9e1
checkstyle complaint package name update
Abhishekkr3003 58f1b46
Merge branch 'main' into aerospike-client-instrumentation
Abhishekkr3003 ec950dc
changes tests to include server close
Abhishekkr3003 14f1109
refactors tests
Abhishekkr3003 4133b58
removes unuseful scopes, local variables and refactors metrics
Abhishekkr3003 b4af69a
adds aerospike metrics test and adds check for experimental-span-attr…
Abhishekkr3003 d1818c1
adds muzzle assert inverse
Abhishekkr3003 e82bdcb
removes :test file
Abhishekkr3003 7c17dfc
Merge branch 'main' into aerospike-client-instrumentation
Abhishekkr3003 5da5b5b
Merge branch 'main' into aerospike-client-instrumentation
Abhishekkr3003 5059c8e
refactors metrics into javaagent and updates metrics test and removes…
Abhishekkr3003 93da28f
updates build.gradle
Abhishekkr3003 a30b6d7
Merge branch 'main' into aerospike-client-instrumentation
Abhishekkr3003 7f84218
minor refactoring
Abhishekkr3003 afda86d
Merge branch 'main' into aerospike-client-instrumentation
Abhishekkr3003 0ef5f40
restructure the modules to v7.0.0
Abhishekkr3003 3a3e509
adds readme for system properties
Abhishekkr3003 7d2f3a5
Merge branch 'main' into aerospike-client-instrumentation
Abhishekkr3003 cc92b86
refactors aerospike module
Abhishekkr3003 453c2b9
fixes errors
Abhishekkr3003 cfc0227
Merge branch 'main' into aerospike-client-instrumentation
Abhishekkr3003 3b6ab9b
applies spotless fixes
Abhishekkr3003 c34b20d
refactoring module a level up
Abhishekkr3003 72c35de
fixes muzzle, refactors module, updates classLoadMatcher and added doc
Abhishekkr3003 79765c5
removes library version check
Abhishekkr3003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
42 changes: 42 additions & 0 deletions
42
instrumentation/aerospike-client/javaagent/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("com.aerospike") | ||
module.set("aerospike-client") | ||
versions.set("[7.1.0,)") | ||
assertInverse.set(true) | ||
} | ||
} | ||
|
||
val latestDepTest = findProperty("testLatestDeps") as Boolean | ||
|
||
dependencies { | ||
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") | ||
jvmArgs("-Dotel.instrumentation.aerospike.experimental-span-attributes=true") | ||
jvmArgs("-Dotel.instrumentation.aerospike.experimental-metrics=true") | ||
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientAttributeExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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.internal.AerospikeRequest; | ||
import io.opentelemetry.javaagent.instrumentation.aerospike.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); | ||
} | ||
} | ||
} |
128 changes: 128 additions & 0 deletions
128
.../io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; | ||
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; | ||
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.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; | ||
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(); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...entelemetry/javaagent/instrumentation/aerospike/AerospikeClientInstrumentationModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.aerospike; | ||
|
||
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.metrics.LatencyType"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return asList( | ||
new AerospikeClientInstrumentation(), | ||
new SyncCommandInstrumentation(), | ||
new AsyncCommandInstrumentation()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ava/io/opentelemetry/javaagent/instrumentation/aerospike/AerospikeDbAttributesGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter; | ||
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<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; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...o/opentelemetry/javaagent/instrumentation/aerospike/AerospikeNetworkAttributesGetter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
import com.aerospike.client.cluster.Node; | ||
import io.opentelemetry.instrumentation.api.semconv.network.NetworkAttributesGetter; | ||
import io.opentelemetry.javaagent.instrumentation.aerospike.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; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
just
library("com.aerospike:aerospike-client:7.1.0")
would be enough, when latest dep tests are run version forlibrary
dependencies is automatically changed to latest