spring-cloud - Why isn't Kafka ProducerListener logging trace id and span id?
问题描述
I have a Kafka instance and a simple spring boot application with one REST controller and a ProducerListener
bean. The controller accepts a simple String
message and sends it to Kafka via KafkaTemplate
. I want the ProducerListener
to log an info message, but the trace id and span id is missing. In my opinion, it should be included in the log.
I use Spring Cloud Sleuth and Spring Kafka starters.
The message itself is successfully sent via Kafka topic to another spring boot application that gets the trace id correctly, so I assume that the problem is related just to the ProducerListener
.
Debugging
I have tried debugging the code and I ended up in the method TracingProducer.send(..)
. The span instance there is NoopSpan
(this was weird) and because of that the TracingCallback
doesn't wrap the Callback
and the tracing information gets lost. There are some nasty bit operations that I couldn't understand. The jar was this one brave-instrumentation-kafka-clients-5.7.0.jar
The code
The controller
@PostMapping("/pass-to-kafka")
public void passToKafka(@RequestBody String message) {
logger.info("This log message has trace id and span id");
kafkaTemplate.send("my-test-topic", message);
}
The producer listener
@Bean
public ProducerListener myProducerListener() {
return new ProducerListener<>() {
@Override
public void onSuccess(ProducerRecord producerRecord, RecordMetadata recordMetadata) {
logger.info("This log message is missing trace id and span id");
}
};
}
The project with the code is on GitHub: https://github.com/vaclavnemec/kafka-sleuth-problem
I expect the info message to write out trace id and span id. It should be the same values in both of the loggers.
INFO [bar,208706b5c40f8e93,208706b5c40f8e93,false] com.example.demo.Controller: This log message has trace id and span id
.
.
.
INFO [bar,,,] com.example.demo.DemoApplication: This log message is missing trace id and span id
解决方案
请spring.sleuth.probability=1.0
按照文档和自述文件中的说明进行设置。然后,您将打开跟踪。
推荐阅读
- python - 函数被读取为变量并在 Python 中工作
- python - Python mysql复制 - 缺少数据
- vb.net - 使用类层次结构创建对象列表时出现问题。VB.net
- python - 从二进制作为浮点数(每个数字 4 个字节)读取到 csv 文件
- python - 为什么这个 django 表单无效?
- react-native - 在 React Native 中重置应用程序或状态
- mysql - node.js mysql不返回结果
- vb.net - 具有类属性的 EWS 电子邮件中的 VB.Net 超链接
- json - Marshal to JSON 结构扩展了另一个具有相同字段标签的结构
- python - 在 Python 3 中,计算来自命令行可执行文件的二进制输出的校验和