Remove unnecessary parameter (#3955)

This commit is contained in:
Trask Stalnaker 2021-08-25 21:51:12 -07:00 committed by GitHub
parent b5aec6a2e0
commit dc2442ce75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 13 deletions

View File

@ -61,7 +61,7 @@ public class KafkaConsumerInstrumentation implements TypeInstrumentation {
public static void wrap( public static void wrap(
@Advice.Return(readOnly = false) Iterable<ConsumerRecord<?, ?>> iterable) { @Advice.Return(readOnly = false) Iterable<ConsumerRecord<?, ?>> iterable) {
if (iterable != null) { if (iterable != null) {
iterable = new TracingIterable(iterable, consumerInstrumenter()); iterable = new TracingIterable(iterable);
} }
} }
} }
@ -72,7 +72,7 @@ public class KafkaConsumerInstrumentation implements TypeInstrumentation {
@Advice.OnMethodExit(suppress = Throwable.class) @Advice.OnMethodExit(suppress = Throwable.class)
public static void wrap(@Advice.Return(readOnly = false) List<ConsumerRecord<?, ?>> iterable) { public static void wrap(@Advice.Return(readOnly = false) List<ConsumerRecord<?, ?>> iterable) {
if (iterable != null) { if (iterable != null) {
iterable = new TracingList(iterable, consumerInstrumenter()); iterable = new TracingList(iterable);
} }
} }
} }

View File

@ -5,20 +5,17 @@
package io.opentelemetry.javaagent.instrumentation.kafkaclients; package io.opentelemetry.javaagent.instrumentation.kafkaclients;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; import static io.opentelemetry.javaagent.instrumentation.kafkaclients.KafkaSingletons.consumerInstrumenter;
import java.util.Iterator; import java.util.Iterator;
import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecord;
public class TracingIterable implements Iterable<ConsumerRecord<?, ?>> { public class TracingIterable implements Iterable<ConsumerRecord<?, ?>> {
private final Iterable<ConsumerRecord<?, ?>> delegate; private final Iterable<ConsumerRecord<?, ?>> delegate;
private final Instrumenter<ConsumerRecord<?, ?>, Void> instrumenter;
private boolean firstIterator = true; private boolean firstIterator = true;
public TracingIterable( public TracingIterable(Iterable<ConsumerRecord<?, ?>> delegate) {
Iterable<ConsumerRecord<?, ?>> delegate,
Instrumenter<ConsumerRecord<?, ?>, Void> instrumenter) {
this.delegate = delegate; this.delegate = delegate;
this.instrumenter = instrumenter;
} }
@Override @Override
@ -28,7 +25,7 @@ public class TracingIterable implements Iterable<ConsumerRecord<?, ?>> {
// However, this is not thread-safe, but usually the first (hopefully only) traversal of // However, this is not thread-safe, but usually the first (hopefully only) traversal of
// ConsumerRecords is performed in the same thread that called poll() // ConsumerRecords is performed in the same thread that called poll()
if (firstIterator) { if (firstIterator) {
it = new TracingIterator(delegate.iterator(), instrumenter); it = new TracingIterator(delegate.iterator(), consumerInstrumenter());
firstIterator = false; firstIterator = false;
} else { } else {
it = delegate.iterator(); it = delegate.iterator();

View File

@ -5,7 +5,6 @@
package io.opentelemetry.javaagent.instrumentation.kafkaclients; package io.opentelemetry.javaagent.instrumentation.kafkaclients;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
@ -14,9 +13,8 @@ import org.apache.kafka.clients.consumer.ConsumerRecord;
public class TracingList extends TracingIterable implements List<ConsumerRecord<?, ?>> { public class TracingList extends TracingIterable implements List<ConsumerRecord<?, ?>> {
private final List<ConsumerRecord<?, ?>> delegate; private final List<ConsumerRecord<?, ?>> delegate;
public TracingList( public TracingList(List<ConsumerRecord<?, ?>> delegate) {
List<ConsumerRecord<?, ?>> delegate, Instrumenter<ConsumerRecord<?, ?>, Void> instrumenter) { super(delegate);
super(delegate, instrumenter);
this.delegate = delegate; this.delegate = delegate;
} }