Skip to content
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

Improve rediscala instrumentation #10301

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion instrumentation/rediscala-1.8/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,19 @@ muzzle {
versions.set("[1.9.0,)")
assertInverse.set(true)
}

pass {
group.set("io.github.rediscala")
module.set("rediscala_2.13")
versions.set("[1.10.0,)")
assertInverse.set(true)
}
}

dependencies {
library("com.github.etaty:rediscala_2.11:1.8.0")

latestDepTestLibrary("com.github.etaty:rediscala_2.13:+")
latestDepTestLibrary("io.github.rediscala:rediscala_2.13:+")
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import redis.ActorRequest;
import redis.BufferedRequest;
import redis.RedisCommand;
import redis.Request;
import redis.RoundRobinPoolRequest;
import scala.concurrent.ExecutionContext;
import scala.concurrent.Future;

Expand Down Expand Up @@ -74,18 +78,29 @@ public static void onEnter(

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
@Advice.This Object action,
@Advice.Argument(0) RedisCommand<?, ?> cmd,
@Advice.Local("otelContext") Context context,
@Advice.Local("otelScope") Scope scope,
@Advice.Thrown Throwable throwable,
@Advice.FieldValue("executionContext") ExecutionContext ctx,
@Advice.Return(readOnly = false) Future<Object> responseFuture) {

if (scope == null) {
return;
}
scope.close();

ExecutionContext ctx = null;
if (action instanceof ActorRequest) {
ctx = ((ActorRequest) action).executionContext();
} else if (action instanceof Request) {
ctx = ((Request) action).executionContext();
} else if (action instanceof BufferedRequest) {
ctx = ((BufferedRequest) action).executionContext();
} else if (action instanceof RoundRobinPoolRequest) {
ctx = ((RoundRobinPoolRequest) action).executionContext();
}

if (throwable != null) {
instrumenter().end(context, cmd, null, throwable);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import akka.actor.ActorSystem
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import io.opentelemetry.semconv.SemanticAttributes
import org.testcontainers.containers.GenericContainer
Expand All @@ -26,23 +25,44 @@ class RediscalaClientTest extends AgentInstrumentationSpecification {
int port

@Shared
ActorSystem system
def system

@Shared
RedisClient redisClient

def setupSpec() {
redisServer.start()
port = redisServer.getMappedPort(6379)
system = ActorSystem.create()
redisClient = new RedisClient("localhost",
port,
Option.apply(null),
Option.apply(null),
"RedisClient",
Option.apply(null),
system,
new RedisDispatcher("rediscala.rediscala-client-worker-dispatcher"))
// latest has separate artifacts for akka an pekko, currently latestDepTestLibrary picks the
// pekko one
try {
def clazz = Class.forName("akka.actor.ActorSystem")
system = clazz.getMethod("create").invoke(null)
} catch (ClassNotFoundException exception) {
def clazz = Class.forName("org.apache.pekko.actor.ActorSystem")
system = clazz.getMethod("create").invoke(null)
}
// latest RedisClient constructor takes username as argument
if (RedisClient.metaClass.getMetaMethod("username") != null) {
redisClient = new RedisClient("localhost",
port,
Option.apply(null),
Option.apply(null),
Option.apply(null),
"RedisClient",
Option.apply(null),
system,
new RedisDispatcher("rediscala.rediscala-client-worker-dispatcher"))
} else {
redisClient = new RedisClient("localhost",
port,
Option.apply(null),
Option.apply(null),
"RedisClient",
Option.apply(null),
system,
new RedisDispatcher("rediscala.rediscala-client-worker-dispatcher"))
}
}

def cleanupSpec() {
Expand Down
Loading