From 78c75b7e607e63a0360e053c9a698cbd7ac913f4 Mon Sep 17 00:00:00 2001 From: Ales Justin Date: Tue, 28 Sep 2021 10:54:24 +0200 Subject: [PATCH] Apply feedback, #3. --- .../kafkaclients/KafkaSingletons.java | 2 +- .../kafkaclients/KafkaTracing.java | 10 +++-- .../kafkaclients/KafkaTracingBuilder.java | 25 ++++++------ .../kafkaclients/KafkaTracingHolder.java | 2 +- .../src/test/resources/log4j.properties | 5 --- .../kafkastreams/KafkaStreamsSingletons.java | 39 +------------------ 6 files changed, 25 insertions(+), 58 deletions(-) delete mode 100644 instrumentation/kafka-clients/kafka-clients-0.11/library/src/test/resources/log4j.properties diff --git a/instrumentation/kafka-clients/kafka-clients-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/KafkaSingletons.java b/instrumentation/kafka-clients/kafka-clients-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/KafkaSingletons.java index 8fc22f5a203d..4756a7e3727a 100644 --- a/instrumentation/kafka-clients/kafka-clients-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/KafkaSingletons.java +++ b/instrumentation/kafka-clients/kafka-clients-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkaclients/KafkaSingletons.java @@ -12,7 +12,7 @@ import org.apache.kafka.clients.producer.ProducerRecord; public final class KafkaSingletons { - public static final String INSTRUMENTATION_NAME = "io.opentelemetry.kafka-clients-0.11.javaagent"; + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.kafka-clients-0.11"; private static final Instrumenter, Void> PRODUCER_INSTRUMENTER = KafkaUtils.buildProducerInstrumenter(INSTRUMENTATION_NAME); diff --git a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracing.java b/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracing.java index ccdfbe794e43..1f7ff44b36fd 100644 --- a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracing.java +++ b/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracing.java @@ -24,8 +24,6 @@ import org.slf4j.LoggerFactory; public class KafkaTracing { - public static final String INSTRUMENTATION_NAME = "io.opentelemetry.kafka-clients-0.11.library"; - private static final Logger logger = LoggerFactory.getLogger(KafkaTracing.class); private static final TextMapGetter GETTER = new KafkaHeadersGetter(); @@ -42,7 +40,13 @@ public class KafkaTracing { this.consumerProcessInstrumenter = consumerProcessInstrumenter; } - public static KafkaTracingBuilder create(OpenTelemetry openTelemetry) { + /** Returns a new {@link KafkaTracing} configured with the given {@link OpenTelemetry}. */ + public static KafkaTracing create(OpenTelemetry openTelemetry) { + return newBuilder(openTelemetry).build(); + } + + /** Returns a new {@link KafkaTracingBuilder} configured with the given {@link OpenTelemetry}. */ + public static KafkaTracingBuilder newBuilder(OpenTelemetry openTelemetry) { return new KafkaTracingBuilder(openTelemetry); } diff --git a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingBuilder.java b/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingBuilder.java index 40ef7101e883..cc0d1882efbd 100644 --- a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingBuilder.java +++ b/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingBuilder.java @@ -16,36 +16,39 @@ import org.apache.kafka.clients.producer.ProducerRecord; public class KafkaTracingBuilder { + private static final String INSTRUMENTATION_NAME = "io.opentelemetry.kafka-clients-0.11"; + private final OpenTelemetry openTelemetry; - private final List, Void>> producerExtractors = - new ArrayList<>(); - private final List, Void>> consumerProcessExtractors = + private final List, Void>> producerAttributesExtractors = new ArrayList<>(); + private final List, Void>> + consumerProcessAttributesExtractors = new ArrayList<>(); KafkaTracingBuilder(OpenTelemetry openTelemetry) { this.openTelemetry = Objects.requireNonNull(openTelemetry); } - public void addProducerExtractors(AttributesExtractor, Void> extractor) { - producerExtractors.add(extractor); + public void addProducerAttributesExtractors( + AttributesExtractor, Void> extractor) { + producerAttributesExtractors.add(extractor); } - public void addConsumerProcessExtractors( + public void addConsumerAttributesProcessExtractors( AttributesExtractor, Void> extractor) { - consumerProcessExtractors.add(extractor); + consumerProcessAttributesExtractors.add(extractor); } @SuppressWarnings("unchecked") public KafkaTracing build() { return new KafkaTracing( KafkaUtils.buildProducerInstrumenter( - KafkaTracing.INSTRUMENTATION_NAME, + INSTRUMENTATION_NAME, openTelemetry, - producerExtractors.toArray(new AttributesExtractor[0])), + producerAttributesExtractors.toArray(new AttributesExtractor[0])), KafkaUtils.buildConsumerOperationInstrumenter( - KafkaTracing.INSTRUMENTATION_NAME, + INSTRUMENTATION_NAME, openTelemetry, MessageOperation.RECEIVE, - consumerProcessExtractors.toArray(new AttributesExtractor[0]))); + consumerProcessAttributesExtractors.toArray(new AttributesExtractor[0]))); } } diff --git a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingHolder.java b/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingHolder.java index 6d75e1469592..ea45acd51af7 100644 --- a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingHolder.java +++ b/instrumentation/kafka-clients/kafka-clients-0.11/library/src/main/java/io/opentelemetry/instrumentation/kafkaclients/KafkaTracingHolder.java @@ -13,7 +13,7 @@ abstract class KafkaTracingHolder { public synchronized KafkaTracing getTracing() { if (tracing == null) { - tracing = KafkaTracing.create(GlobalOpenTelemetry.get()).build(); + tracing = KafkaTracing.create(GlobalOpenTelemetry.get()); } return tracing; } diff --git a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/test/resources/log4j.properties b/instrumentation/kafka-clients/kafka-clients-0.11/library/src/test/resources/log4j.properties deleted file mode 100644 index 1ea4751367ed..000000000000 --- a/instrumentation/kafka-clients/kafka-clients-0.11/library/src/test/resources/log4j.properties +++ /dev/null @@ -1,5 +0,0 @@ -# Set root logger level to INFO and its only appender to C1. -log4j.rootLogger=INFO, A1 - -# C1 is set to be a ConsoleAppender. -log4j.appender.C1=org.apache.log4j.ConsoleAppender diff --git a/instrumentation/kafka-streams-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkastreams/KafkaStreamsSingletons.java b/instrumentation/kafka-streams-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkastreams/KafkaStreamsSingletons.java index 3dad14fb4be1..d3563308e92d 100644 --- a/instrumentation/kafka-streams-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkastreams/KafkaStreamsSingletons.java +++ b/instrumentation/kafka-streams-0.11/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kafkastreams/KafkaStreamsSingletons.java @@ -5,20 +5,8 @@ package io.opentelemetry.javaagent.instrumentation.kafkastreams; -import io.opentelemetry.api.GlobalOpenTelemetry; -import io.opentelemetry.instrumentation.api.config.ExperimentalConfig; import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; -import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.SpanLinksExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; -import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessageOperation; -import io.opentelemetry.instrumentation.api.instrumenter.messaging.MessagingSpanNameExtractor; -import io.opentelemetry.instrumentation.kafka.KafkaConsumerAdditionalAttributesExtractor; -import io.opentelemetry.instrumentation.kafka.KafkaConsumerAttributesExtractor; -import io.opentelemetry.instrumentation.kafka.KafkaConsumerExperimentalAttributesExtractor; -import io.opentelemetry.instrumentation.kafka.KafkaConsumerRecordGetter; -import io.opentelemetry.instrumentation.kafka.KafkaPropagation; +import io.opentelemetry.instrumentation.kafka.KafkaUtils; import org.apache.kafka.clients.consumer.ConsumerRecord; public final class KafkaStreamsSingletons { @@ -28,30 +16,7 @@ public final class KafkaStreamsSingletons { private static final Instrumenter, Void> INSTRUMENTER = buildInstrumenter(); private static Instrumenter, Void> buildInstrumenter() { - KafkaConsumerAttributesExtractor attributesExtractor = - new KafkaConsumerAttributesExtractor(MessageOperation.PROCESS); - SpanNameExtractor> spanNameExtractor = - MessagingSpanNameExtractor.create(attributesExtractor); - - InstrumenterBuilder, Void> builder = - Instrumenter., Void>newBuilder( - GlobalOpenTelemetry.get(), INSTRUMENTATION_NAME, spanNameExtractor) - .addAttributesExtractor(attributesExtractor) - .addAttributesExtractor(new KafkaConsumerAdditionalAttributesExtractor()); - if (KafkaConsumerExperimentalAttributesExtractor.isEnabled()) { - builder.addAttributesExtractor(new KafkaConsumerExperimentalAttributesExtractor()); - } - - if (!KafkaPropagation.isPropagationEnabled()) { - return builder.newInstrumenter(SpanKindExtractor.alwaysConsumer()); - } else if (ExperimentalConfig.get().suppressMessagingReceiveSpans()) { - return builder.newConsumerInstrumenter(new KafkaConsumerRecordGetter()); - } else { - builder.addSpanLinksExtractor( - SpanLinksExtractor.fromUpstreamRequest( - GlobalOpenTelemetry.getPropagators(), new KafkaConsumerRecordGetter())); - return builder.newInstrumenter(SpanKindExtractor.alwaysConsumer()); - } + return KafkaUtils.buildConsumerProcessInstrumenter(INSTRUMENTATION_NAME); } public static Instrumenter, Void> instrumenter() {