|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.javaagent.instrumentation.pulsar.v2_8; |
| 7 | + |
| 8 | +import static net.bytebuddy.matcher.ElementMatchers.isPublic; |
| 9 | +import static net.bytebuddy.matcher.ElementMatchers.named; |
| 10 | +import static net.bytebuddy.matcher.ElementMatchers.takesArgument; |
| 11 | +import static net.bytebuddy.matcher.ElementMatchers.takesArguments; |
| 12 | + |
| 13 | +import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; |
| 14 | +import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; |
| 15 | +import io.opentelemetry.javaagent.instrumentation.pulsar.v2_8.telemetry.PulsarSingletons; |
| 16 | +import java.util.concurrent.CompletableFuture; |
| 17 | +import net.bytebuddy.asm.Advice; |
| 18 | +import net.bytebuddy.description.type.TypeDescription; |
| 19 | +import net.bytebuddy.matcher.ElementMatcher; |
| 20 | + |
| 21 | +public class TransactionImplInstrumentation implements TypeInstrumentation { |
| 22 | + @Override |
| 23 | + public ElementMatcher<TypeDescription> typeMatcher() { |
| 24 | + return named("org.apache.pulsar.client.impl.transaction.TransactionImpl"); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public void transform(TypeTransformer transformer) { |
| 29 | + transformer.applyAdviceToMethod( |
| 30 | + named("registerProducedTopic") |
| 31 | + .and(isPublic()) |
| 32 | + .and(takesArguments(1)) |
| 33 | + .and(takesArgument(0, String.class)), |
| 34 | + TransactionImplInstrumentation.class.getName() + "$RegisterProducedTopicAdvice"); |
| 35 | + } |
| 36 | + |
| 37 | + @SuppressWarnings("unused") |
| 38 | + public static class RegisterProducedTopicAdvice { |
| 39 | + |
| 40 | + @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) |
| 41 | + public static void after(@Advice.Return(readOnly = false) CompletableFuture<Void> future) { |
| 42 | + future = PulsarSingletons.wrap(future); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments