adriancole commented on a change in pull request #904: Messaging adapter
URL:
https://github.com/apache/incubator-zipkin-brave/pull/904#discussion_r282297193
##########
File path:
instrumentation/kafka-clients/src/main/java/brave/kafka/clients/KafkaTracing.java
##########
@@ -68,35 +78,56 @@ public KafkaTracing build() {
}
}
- final Tracing tracing;
- final Extractor<Headers> extractor;
- final Injector<Headers> injector;
- final Set<String> propagationKeys;
+ final MessagingTracing msgTracing;
final String remoteServiceName;
+ final List<String> propagationKeys;
+ final Extractor<ConsumerRecord> consumerRecordExtractor;
+ final Injector<ConsumerRecord> consumerRecordInjector;
+ final MessagingConsumerHandler<ConsumerRecord> consumerHandler;
+ final Extractor<ProducerRecord> producerRecordExtractor;
+ final Injector<ProducerRecord> producerRecordInjector;
+ final MessagingProducerHandler<ProducerRecord> producerHandler;
KafkaTracing(Builder builder) { // intentionally hidden constructor
- this.tracing = builder.tracing;
- this.extractor = tracing.propagation().extractor(KafkaPropagation.GETTER);
- List<String> keyList = builder.tracing.propagation().keys();
- // Use a more efficient injector if we are only propagating a single header
+ this.msgTracing = builder.msgTracing;
+ this.remoteServiceName = builder.remoteServiceName;
+ this.propagationKeys = msgTracing.tracing().propagation().keys();
+ final Extractor<Headers> extractor =
msgTracing.tracing().propagation().extractor(KafkaPropagation.HEADERS_GETTER);
+ List<String> keyList = msgTracing.tracing().propagation().keys();
+ boolean singleFormat = false;
if (builder.writeB3SingleFormat ||
keyList.equals(Propagation.B3_SINGLE_STRING.keys())) {
TraceContext testExtraction =
extractor.extract(B3_SINGLE_TEST_HEADERS).context();
if (!TEST_CONTEXT.equals(testExtraction)) {
throw new IllegalArgumentException(
"KafkaTracing.Builder.writeB3SingleFormat set, but
Tracing.Builder.propagationFactory cannot parse this format!");
}
- this.injector = KafkaPropagation.B3_SINGLE_INJECTOR;
- } else {
- this.injector = tracing.propagation().injector(KafkaPropagation.SETTER);
+ singleFormat = true;
}
- this.propagationKeys = new LinkedHashSet<>(keyList);
- this.remoteServiceName = builder.remoteServiceName;
+ this.producerRecordInjector = singleFormat ?
KafkaPropagation.B3_SINGLE_INJECTOR_PRODUCER
+ :
msgTracing.tracing().propagation().injector(KafkaPropagation.PRODUCER_RECORD_SETTER);
+ this.producerRecordExtractor =
+
msgTracing.tracing().propagation().extractor(KafkaPropagation.PRODUCER_RECORD_GETTER);
+ this.producerHandler =
+ MessagingProducerHandler.create(msgTracing,
+ TracingProducer.KafkaProducerAdapter.create(this),
+ producerRecordExtractor, producerRecordInjector);
+ this.consumerRecordInjector = singleFormat ?
KafkaPropagation.B3_SINGLE_INJECTOR_CONSUMER
+ : msgTracing.tracing()
+ .propagation()
+ .injector(KafkaPropagation.CONSUMER_RECORD_SETTER);
+ this.consumerRecordExtractor =
+
msgTracing.tracing().propagation().extractor(KafkaPropagation.CONSUMER_RECORD_GETTER);
+ this.consumerHandler =
+ MessagingConsumerHandler.create(msgTracing,
+ TracingConsumer.KafkaConsumerAdapter.create(this),
+ consumerRecordExtractor, consumerRecordInjector);
+
}
/**
* Extracts or creates a {@link Span.Kind#CONSUMER} span for each message
received. This span is
* injected onto each message so it becomes the parent when a processor
later calls {@link
- * #nextSpan(ConsumerRecord)}.
+ * // #nextSpan(ConsumerRecord)}.
Review comment:
```suggestion
* #nextSpan(ConsumerRecord)}.
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]