-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instrumentation for redisson 3.17.2 (#6096)
* Instrumentation for redisson 3.17.2 * cross test instrumentation * split at 3.17.0, assert inverse * Apply suggestions from code review Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com> Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
- Loading branch information
Showing
28 changed files
with
386 additions
and
62 deletions.
There are no files selected for viewing
39 changes: 0 additions & 39 deletions
39
...src/main/java/io/opentelemetry/javaagent/instrumentation/redisson/RedissonSingletons.java
This file was deleted.
Oops, something went wrong.
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
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
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
23 changes: 23 additions & 0 deletions
23
...ain/java/io/opentelemetry/javaagent/instrumentation/redisson/v3_0/RedissonSingletons.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,23 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.redisson.v3_0; | ||
|
||
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; | ||
import io.opentelemetry.javaagent.instrumentation.redisson.RedissonInstrumenterFactory; | ||
import io.opentelemetry.javaagent.instrumentation.redisson.RedissonRequest; | ||
|
||
public final class RedissonSingletons { | ||
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.redisson-3.0"; | ||
|
||
private static final Instrumenter<RedissonRequest, Void> INSTRUMENTER = | ||
RedissonInstrumenterFactory.createInstrumenter(INSTRUMENTATION_NAME); | ||
|
||
public static Instrumenter<RedissonRequest, Void> instrumenter() { | ||
return INSTRUMENTER; | ||
} | ||
|
||
private RedissonSingletons() {} | ||
} |
7 changes: 7 additions & 0 deletions
7
...umentation/redisson/redisson-3.0/javaagent/src/test/groovy/RedissonAsyncClientTest.groovy
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,7 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
class RedissonAsyncClientTest extends AbstractRedissonAsyncClientTest { | ||
} |
7 changes: 7 additions & 0 deletions
7
instrumentation/redisson/redisson-3.0/javaagent/src/test/groovy/RedissonClientTest.groovy
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,7 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
class RedissonClientTest extends AbstractRedissonClientTest { | ||
} |
30 changes: 30 additions & 0 deletions
30
instrumentation/redisson/redisson-3.17/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,30 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("org.redisson") | ||
module.set("redisson") | ||
versions.set("[3.17.0,)") | ||
assertInverse.set(true) | ||
} | ||
} | ||
|
||
dependencies { | ||
library("org.redisson:redisson:3.17.0") | ||
|
||
implementation(project(":instrumentation:redisson:redisson-common:javaagent")) | ||
|
||
compileOnly("com.google.auto.value:auto-value-annotations") | ||
annotationProcessor("com.google.auto.value:auto-value") | ||
|
||
testInstrumentation(project(":instrumentation:redisson:redisson-3.0:javaagent")) | ||
|
||
testImplementation(project(":instrumentation:redisson:redisson-common:testing")) | ||
} | ||
|
||
tasks.test { | ||
systemProperty("testLatestDeps", findProperty("testLatestDeps") as Boolean) | ||
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].getService()) | ||
} |
44 changes: 44 additions & 0 deletions
44
...entelemetry/javaagent/instrumentation/redisson/v3_17/RedisCommandDataInstrumentation.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.redisson.v3_17; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.opentelemetry.javaagent.instrumentation.redisson.CompletableFutureWrapper; | ||
import java.util.concurrent.CompletableFuture; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class RedisCommandDataInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return namedOneOf( | ||
"org.redisson.client.protocol.CommandData", "org.redisson.client.protocol.CommandsData"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isConstructor().and(takesArgument(0, CompletableFuture.class)), | ||
this.getClass().getName() + "$WrapCompletableFutureAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class WrapCompletableFutureAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter( | ||
@Advice.Argument(value = 0, readOnly = false) CompletableFuture<?> completableFuture) { | ||
completableFuture = CompletableFutureWrapper.wrap(completableFuture); | ||
} | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...pentelemetry/javaagent/instrumentation/redisson/v3_17/RedisConnectionInstrumentation.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,84 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.redisson.v3_17; | ||
|
||
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext; | ||
import static io.opentelemetry.javaagent.instrumentation.redisson.v3_17.RedissonSingletons.instrumenter; | ||
import static net.bytebuddy.matcher.ElementMatchers.isMethod; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.opentelemetry.javaagent.instrumentation.redisson.EndOperationListener; | ||
import io.opentelemetry.javaagent.instrumentation.redisson.PromiseWrapper; | ||
import io.opentelemetry.javaagent.instrumentation.redisson.RedissonRequest; | ||
import java.net.InetSocketAddress; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import org.redisson.client.RedisConnection; | ||
|
||
public class RedisConnectionInstrumentation implements TypeInstrumentation { | ||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("org.redisson.client.RedisConnection"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isMethod().and(named("send")), this.getClass().getName() + "$SendAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class SendAdvice { | ||
|
||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void onEnter( | ||
@Advice.This RedisConnection connection, | ||
@Advice.Argument(0) Object arg, | ||
@Advice.Local("otelRequest") RedissonRequest request, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
|
||
Context parentContext = currentContext(); | ||
InetSocketAddress remoteAddress = (InetSocketAddress) connection.getChannel().remoteAddress(); | ||
request = RedissonRequest.create(remoteAddress, arg); | ||
PromiseWrapper<?> promise = request.getPromiseWrapper(); | ||
if (promise == null) { | ||
return; | ||
} | ||
if (!instrumenter().shouldStart(parentContext, request)) { | ||
return; | ||
} | ||
|
||
context = instrumenter().start(parentContext, request); | ||
scope = context.makeCurrent(); | ||
|
||
promise.setEndOperationListener(new EndOperationListener<>(instrumenter(), context, request)); | ||
} | ||
|
||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) | ||
public static void stopSpan( | ||
@Advice.Thrown Throwable throwable, | ||
@Advice.Local("otelRequest") RedissonRequest request, | ||
@Advice.Local("otelContext") Context context, | ||
@Advice.Local("otelScope") Scope scope) { | ||
|
||
if (scope == null) { | ||
return; | ||
} | ||
scope.close(); | ||
|
||
if (throwable != null) { | ||
instrumenter().end(context, request, null, throwable); | ||
} | ||
// span ended in EndOperationListener | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...opentelemetry/javaagent/instrumentation/redisson/v3_17/RedissonInstrumentationModule.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,33 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.redisson.v3_17; | ||
|
||
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 RedissonInstrumentationModule extends InstrumentationModule { | ||
|
||
public RedissonInstrumentationModule() { | ||
super("redisson", "redisson-3.17"); | ||
} | ||
|
||
@Override | ||
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() { | ||
return hasClassesNamed("org.redisson.api.RFunction"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return asList(new RedisConnectionInstrumentation(), new RedisCommandDataInstrumentation()); | ||
} | ||
} |
Oops, something went wrong.