io.opentelemetry.javaagent.instrumentation.mongoasync.v3_3.BaseClusterInstrumentation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-javaagent-mongo-async-3.3 Show documentation
Show all versions of opentelemetry-javaagent-mongo-async-3.3 Show documentation
Instrumentation of Java libraries using OpenTelemetry.
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.mongoasync.v3_3;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import com.mongodb.async.SingleResultCallback;
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
final class BaseClusterInstrumentation implements TypeInstrumentation {
@Override
public ElementMatcher typeMatcher() {
return named("com.mongodb.connection.BaseCluster");
}
@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isMethod()
.and(isPublic())
.and(named("selectServerAsync"))
.and(takesArgument(0, named("com.mongodb.selector.ServerSelector")))
.and(takesArgument(1, named("com.mongodb.async.SingleResultCallback"))),
this.getClass().getName() + "$SingleResultCallbackArg1Advice");
}
@SuppressWarnings("unused")
public static class SingleResultCallbackArg1Advice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static void wrapCallback(
@Advice.Argument(value = 1, readOnly = false) SingleResultCallback