CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: String similarity Open both answers

Possible Plagiarism

Reposted on 2023-04-27
by aksh1618

Original Post

Original - Posted on 2023-04-27
by aksh1618



            
Present in both answers; Present only in the new answer; Present only in the old answer;

**TL;DR**: Try adding this property: ```property # Disable addition of B3 headers in kafka producer records spring.sleuth.messaging.enabled=false ```
**Full answer**: I tried addingg `props.put(JsonSerializer.ADD_TYPE_INFO_HEADERS, false);`, but it was still not working. On further debugging inside the send method I discovered that a `B3` header was part of the final record being sent. B3 headers are used for tracing purposes, and indeed I had sleuth as part of the project.
To remove this header, I tried disabling kafka tracing related `AutoConfiguration` classes, but that didn't work. I also tried setting the following properties, neither of which worked:
```properties # These didn't work #spring.sleuth.kafka.enabled=false #spring.sleuth.messaging.kafka.streams.enabled=false ```
After some further debugging + trial & errors, I discovered that the produce was being wrapped via a bean post processor, roughly this flow:
```none org.springframework.cloud.sleuth.brave.instrument.messaging.KafkaFactoryBeanPostProcessor::postProcessAfterInitialization -> org.springframework.cloud.sleuth.brave.instrument.messaging.TraceProducerPostProcessor::wrapInTracing -> brave.kafka.clients.KafkaTracing::producerInjector -> brave.kafka.clients.KafkaProducerRequest::SETTER::put ```
I still couldn't figure out how to disable `KafkaFactoryBeanPostProcessor`, but I saw an annotation defined in the same package: `ConditionalOnMessagingEnabled`, which depended on a the following property, setting which finally worked!
```properties # Disable addition of B3 headers in kafka producer records spring.sleuth.messaging.enabled=false ```
**TL;DR**: Try adding this property: ```property # Disable addition of B3 headers in kafka producer records spring.sleuth.messaging.enabled=false ```
**Full answer**: I tried addingg `props.put(JsonSerializer.ADD_TYPE_INFO_HEADERS, false);`, but it was still not working. On further debugging inside the send method I discovered that a `B3` header was part of the final record being sent. B3 headers are used for tracing purposes, and indeed I had sleuth as part of the project.
To remove this header, I tried disabling kafka tracing related `AutoConfiguration` classes, but that didn't work. I also tried setting the following properties, neither of which worked:
```properties # These didn't work #spring.sleuth.kafka.enabled=false #spring.sleuth.messaging.kafka.streams.enabled=false ```
After some further debugging + trial & errors, I discovered that the produce was being wrapped via a bean post processor, roughly this flow:
```none org.springframework.cloud.sleuth.brave.instrument.messaging.KafkaFactoryBeanPostProcessor::postProcessAfterInitialization -> org.springframework.cloud.sleuth.brave.instrument.messaging.TraceProducerPostProcessor::wrapInTracing -> brave.kafka.clients.KafkaTracing::producerInjector -> brave.kafka.clients.KafkaProducerRequest::SETTER::put ```
I still couldn't figure out how to disable `KafkaFactoryBeanPostProcessor`, but I saw an annotation defined in the same package: `ConditionalOnMessagingEnabled`, which depended on a the following property, setting which finally worked!
```properties # Disable addition of B3 headers in kafka producer records spring.sleuth.messaging.enabled=false ```

        
Present in both answers; Present only in the new answer; Present only in the old answer;