-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instrumentation for hibernate reactive (#9304)
- Loading branch information
Showing
15 changed files
with
356 additions
and
71 deletions.
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
83 changes: 83 additions & 0 deletions
83
instrumentation/hibernate/hibernate-reactive-1.0/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,83 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("org.hibernate.reactive") | ||
module.set("hibernate-reactive-core") | ||
versions.set("(,)") | ||
assertInverse.set(true) | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly("org.hibernate.reactive:hibernate-reactive-core:1.0.0.Final") | ||
|
||
testInstrumentation(project(":instrumentation:netty:netty-4.1:javaagent")) | ||
testInstrumentation(project(":instrumentation:vertx:vertx-sql-client-4.0:javaagent")) | ||
|
||
library("io.vertx:vertx-sql-client:4.4.2") | ||
compileOnly("io.vertx:vertx-codegen:4.4.2") | ||
|
||
testLibrary("io.vertx:vertx-pg-client:4.4.2") | ||
testLibrary("io.vertx:vertx-codegen:4.4.2") | ||
} | ||
|
||
val latestDepTest = findProperty("testLatestDeps") as Boolean | ||
|
||
testing { | ||
suites { | ||
val hibernateReactive1Test by registering(JvmTestSuite::class) { | ||
dependencies { | ||
implementation("org.testcontainers:testcontainers") | ||
if (latestDepTest) { | ||
implementation("org.hibernate.reactive:hibernate-reactive-core:1.+") | ||
implementation("io.vertx:vertx-pg-client:+") | ||
} else { | ||
implementation("org.hibernate.reactive:hibernate-reactive-core:1.0.0.Final") | ||
implementation("io.vertx:vertx-pg-client:4.1.5") | ||
} | ||
} | ||
} | ||
|
||
val hibernateReactive2Test by registering(JvmTestSuite::class) { | ||
dependencies { | ||
implementation("org.testcontainers:testcontainers") | ||
if (latestDepTest) { | ||
implementation("org.hibernate.reactive:hibernate-reactive-core:2.+") | ||
implementation("io.vertx:vertx-pg-client:+") | ||
} else { | ||
implementation("org.hibernate.reactive:hibernate-reactive-core:2.0.0.Final") | ||
implementation("io.vertx:vertx-pg-client:4.4.2") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks { | ||
withType<Test>().configureEach { | ||
usesService(gradle.sharedServices.registrations["testcontainersBuildService"].service) | ||
} | ||
named("compileHibernateReactive2TestJava", JavaCompile::class).configure { | ||
options.release.set(11) | ||
} | ||
val testJavaVersion = | ||
gradle.startParameter.projectProperties.get("testJavaVersion")?.let(JavaVersion::toVersion) | ||
?: JavaVersion.current() | ||
if (testJavaVersion.isJava8) { | ||
named("hibernateReactive2Test", Test::class).configure { | ||
enabled = false | ||
} | ||
if (latestDepTest) { | ||
named("hibernateReactive1Test", Test::class).configure { | ||
enabled = false | ||
} | ||
} | ||
} | ||
|
||
check { | ||
dependsOn(testing.suites) | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
72 changes: 72 additions & 0 deletions
72
...a/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v1_0/ContextOperator.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,72 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.hibernate.reactive.v1_0; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.smallrye.mutiny.Uni; | ||
import io.smallrye.mutiny.operators.UniOperator; | ||
import io.smallrye.mutiny.subscription.UniSubscriber; | ||
import io.smallrye.mutiny.subscription.UniSubscription; | ||
|
||
public final class ContextOperator<T> extends UniOperator<T, T> { | ||
private final Context context; | ||
|
||
public ContextOperator(Uni<? extends T> upstream, Context context) { | ||
super(upstream); | ||
this.context = context; | ||
} | ||
|
||
public static <T> Uni<T> plug(Uni<T> uni) { | ||
if (uni instanceof ContextOperator) { | ||
return uni; | ||
} | ||
Context parentContext = Context.current(); | ||
if (parentContext == Context.root()) { | ||
return uni; | ||
} | ||
|
||
return uni.plug(u -> new ContextOperator<>(u, parentContext)); | ||
} | ||
|
||
@Override | ||
public void subscribe(UniSubscriber<? super T> downstream) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
upstream().subscribe().withSubscriber(new ContextSubscriber<>(downstream, context)); | ||
} | ||
} | ||
|
||
private static class ContextSubscriber<T> implements UniSubscriber<T> { | ||
private final UniSubscriber<? super T> downstream; | ||
private final Context context; | ||
|
||
private ContextSubscriber(UniSubscriber<? super T> downstream, Context context) { | ||
this.downstream = downstream; | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public void onSubscribe(UniSubscription uniSubscription) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
downstream.onSubscribe(uniSubscription); | ||
} | ||
} | ||
|
||
@Override | ||
public void onItem(T t) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
downstream.onItem(t); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Throwable throwable) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
downstream.onFailure(throwable); | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...a/io/opentelemetry/javaagent/instrumentation/hibernate/reactive/v1_0/FunctionWrapper.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,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.hibernate.reactive.v1_0; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import java.util.function.Function; | ||
|
||
public final class FunctionWrapper<T, R> implements Function<T, R> { | ||
private final Function<T, R> delegate; | ||
private final Context context; | ||
|
||
private FunctionWrapper(Function<T, R> delegate, Context context) { | ||
this.delegate = delegate; | ||
this.context = context; | ||
} | ||
|
||
public static <T, R> Function<T, R> wrap(Function<T, R> function) { | ||
if (function instanceof FunctionWrapper) { | ||
return function; | ||
} | ||
Context context = Context.current(); | ||
if (context == Context.root()) { | ||
return function; | ||
} | ||
|
||
return new FunctionWrapper<>(function, context); | ||
} | ||
|
||
@Override | ||
public R apply(T t) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
return delegate.apply(t); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...agent/instrumentation/hibernate/reactive/v1_0/HibernateReactiveInstrumentationModule.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.hibernate.reactive.v1_0; | ||
|
||
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; | ||
|
||
@AutoService(InstrumentationModule.class) | ||
public class HibernateReactiveInstrumentationModule extends InstrumentationModule { | ||
|
||
public HibernateReactiveInstrumentationModule() { | ||
super("hibernate-reactive", "hibernate-reactive-1.0"); | ||
} | ||
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return asList( | ||
new StageSessionFactoryInstrumentation(), new MutinySessionFactoryInstrumentation()); | ||
} | ||
} |
Oops, something went wrong.