Skip to content

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishekkr3003 committed Feb 11, 2024
1 parent a30b6d7 commit 7f84218
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public AerospikeClientInstrumentationModule() {

@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return hasClassesNamed("com.aerospike.client.AerospikeClient");
return hasClassesNamed("com.aerospike.client.AerospikeClient").and(hasClassesNamed("com.aerospike.client.metrics.MetricsPolicy"));
}

@Override
Expand All @@ -35,9 +35,4 @@ public List<TypeInstrumentation> typeInstrumentations() {
new AsyncHandlerInstrumentation(),
new AsyncScanAllCommandInstrumentation());
}

@Override
public boolean isIndyModule() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,11 @@ public void detachAndEnd() {
contextThreadLocal.remove();
}

@SuppressWarnings("unchecked")
public static AerospikeRequestContext current() {
return contextThreadLocal.get();
}

public void endSpan(
Instrumenter<AerospikeRequest, Void> instrumenter,
Context context,
AerospikeRequest request,
Throwable throwable) {
public void endSpan(Instrumenter<AerospikeRequest, Void> instrumenter, Throwable throwable) {
instrumenter.end(context, request, null, throwable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}

Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 7f84218

Please sign in to comment.