Search code examples
springapache-kafkaspring-cloud-sleuthbrave

Brave Tracing in Kafka Headers


In SB2, Brave instruments Kafka messages with B3 headers by default, however I need to change the field names that are injected. E.g. X-B3-TraceId should be myEventTraceId. Is there an easy way to do this? Even some design guidance would help greatly. Wouldnt mind a simple example... KafkaTracing and Injector classes come to mind. Thanks.


Solution

  • I ended up wrapping the producer returned in createProducer() of my custom ProducerFactory in a custom delegate class that implements Producer. My implementation of send() executed after Brave's TracingProducer.send() such that I could modify the tracing headers Brave set in the ProducerRecord headers prior to sending the bits. The same logic applies when consuming.