Skip to content

Commit b039e11

Browse files
committed
Address review comment
1 parent 507350f commit b039e11

File tree

3 files changed

+15
-45
lines changed

3 files changed

+15
-45
lines changed

instrumentation/pulsar/pulsar-2.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/TransactionImplInstrumentation.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
1111
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
1212

13-
import io.opentelemetry.instrumentation.api.internal.Timer;
1413
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1514
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1615
import io.opentelemetry.javaagent.instrumentation.pulsar.v2_8.telemetry.PulsarSingletons;
@@ -31,23 +30,17 @@ public void transform(TypeTransformer transformer) {
3130
named("registerProducedTopic")
3231
.and(isPublic())
3332
.and(takesArguments(1))
34-
.and(takesArgument(0, named("java.lang.String"))),
33+
.and(takesArgument(0, String.class)),
3534
TransactionImplInstrumentation.class.getName() + "$RegisterProducedTopicAdvice");
3635
}
3736

3837
@SuppressWarnings("unused")
3938
public static class RegisterProducedTopicAdvice {
4039

41-
@Advice.OnMethodEnter
42-
public static Timer before() {
43-
return Timer.start();
44-
}
45-
4640
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
4741
public static void after(
48-
@Advice.Enter Timer timer,
4942
@Advice.Return(readOnly = false) CompletableFuture<Void> future) {
50-
future = PulsarSingletons.wrap(future, timer);
43+
future = PulsarSingletons.wrap(future);
5144
}
5245
}
5346
}

instrumentation/pulsar/pulsar-2.8/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/telemetry/PulsarSingletons.java

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public final class PulsarSingletons {
5353
createConsumerBatchReceiveInstrumenter();
5454
private static final Instrumenter<PulsarRequest, Void> PRODUCER_INSTRUMENTER =
5555
createProducerInstrumenter();
56-
private static final Instrumenter<String, Void> TXN_PRODUCE_INSTRUMENTER =
57-
createTxnProduceInstrumenter();
5856

5957
public static Instrumenter<PulsarRequest, Void> consumerProcessInstrumenter() {
6058
return CONSUMER_PROCESS_INSTRUMENTER;
@@ -153,22 +151,6 @@ private static Instrumenter<PulsarRequest, Void> createProducerInstrumenter() {
153151
return builder.buildProducerInstrumenter(MessageTextMapSetter.INSTANCE);
154152
}
155153

156-
private static Instrumenter<String, Void> createTxnProduceInstrumenter() {
157-
InstrumenterBuilder<String, Void> instrumenterBuilder =
158-
Instrumenter.builder(
159-
TELEMETRY, INSTRUMENTATION_NAME, request -> "Txn Produce Register Topic");
160-
return instrumenterBuilder.buildInstrumenter(SpanKindExtractor.alwaysProducer());
161-
}
162-
163-
public static Context startAndEndTxnProduceRegister(
164-
Context parent, Timer timer, Throwable throwable) {
165-
if (!TXN_PRODUCE_INSTRUMENTER.shouldStart(parent, "")) {
166-
return null;
167-
}
168-
return InstrumenterUtil.startAndEnd(
169-
TXN_PRODUCE_INSTRUMENTER, parent, "", null, throwable, timer.startTime(), timer.now());
170-
}
171-
172154
private static <T> AttributesExtractor<T, Void> createMessagingAttributesExtractor(
173155
MessagingAttributesGetter<T, Void> getter, MessageOperation operation) {
174156
return MessagingAttributesExtractor.builder(getter, operation)
@@ -228,22 +210,21 @@ private static Context startAndEndConsumerReceive(
228210
timer.now());
229211
}
230212

231-
public static CompletableFuture<Void> wrap(CompletableFuture<Void> future, Timer timer) {
213+
public static CompletableFuture<Void> wrap(CompletableFuture<Void> future) {
232214
Context parent = Context.current();
233215
CompletableFuture<Void> result = new CompletableFuture<>();
234216
future.whenComplete(
235-
(unused, t) -> {
236-
Context context = startAndEndTxnProduceRegister(parent, timer, t);
237-
runWithContext(
238-
context,
239-
() -> {
240-
if (t != null) {
241-
result.completeExceptionally(t);
242-
} else {
243-
result.complete(null);
244-
}
245-
});
246-
});
217+
(unused, t) ->
218+
runWithContext(
219+
parent,
220+
() -> {
221+
if (t != null) {
222+
result.completeExceptionally(t);
223+
} else {
224+
result.complete(null);
225+
}
226+
})
227+
);
247228

248229
return result;
249230
}

instrumentation/pulsar/pulsar-2.8/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/pulsar/v2_8/PulsarClientTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,9 @@ void testSendMessageWithTxn() throws Exception {
693693
trace ->
694694
trace.hasSpansSatisfyingExactly(
695695
span -> span.hasName("parent1").hasKind(SpanKind.INTERNAL).hasNoParent(),
696-
span ->
697-
span.hasName("Txn Produce Register Topic")
698-
.hasKind(SpanKind.PRODUCER)
699-
.hasParent(trace.getSpan(0)),
700696
span ->
701697
span.hasName(topic + " publish")
702698
.hasKind(SpanKind.PRODUCER)
703-
.hasParent(trace.getSpan(1))));
699+
.hasParent(trace.getSpan(0))));
704700
}
705701
}

0 commit comments

Comments
 (0)