spring-bootapache-kafkaspring-cloud-sleuthzipkinobservability

Zipkin Sender Type and Kafka Topic Not Working After Updating Spring Boot 3


Hi I just update spring boot to version 3 and in my project we are configure zipkin configuration to send span to kafka with specific topic and it not working now

zipkin:
  sender.type: kafka
  kafka.topic: topic-example

is there anyway for Micrometer tracing to configure zipkin the same way in the application.yaml? or any alternative configuration ?

====NEW UPDATE========== I tried another approach :

pom.xml

<!--Observability dependencies-->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-tracing-bridge-otel</artifactId>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-zipkin</artifactId>
        </dependency>
        <dependency>
            <groupId>io.zipkin.reporter2</groupId>
            <artifactId>zipkin-sender-kafka</artifactId>
        </dependency>
        <!--Observability dependencies-->

KafkaConfiguration.java

@Configuration
@EnableConfigurationProperties(KafkaProperties.class)
public class KafkaConfig {

    static String join(List<?> parts) {
        StringBuilder to = new StringBuilder();
        for (int i = 0, length = parts.size(); i < length; i++) {
            to.append(parts.get(i));
            if (i + 1 < length) {
                to.append(',');
            }
        }
        return to.toString();
    }

    @Bean("zipkinSender")
    Sender kafkaSender(KafkaProperties config, Environment environment) {
        // Need to get property value from Environment
        // because when using @VaultPropertySource in reactive web app
        // this bean is initiated before @Value is resolved
        // See gh-1990
        String topic = environment.getProperty("spring.zipkin.kafka.topic", "zipkin");
        Map<String, Object> properties = config.buildProducerProperties();
        properties.put("key.serializer", ByteArraySerializer.class.getName());
        properties.put("value.serializer", ByteArraySerializer.class.getName());
        // Kafka expects the input to be a String, but KafkaProperties returns a list
        Object bootstrapServers = properties.get("bootstrap.servers");
        if (bootstrapServers instanceof List) {
            properties.put("bootstrap.servers", join((List) bootstrapServers));
        }
        return KafkaSender.newBuilder().topic(topic).overrides(properties).build();
    }
}

spring:
  kafka:
    consumer:
      bootstrap-servers: localhost:9092
      group-id: group-id
      auto-offset-reset: earliest
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
    producer:
      bootstrap-servers: localhost:9092
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer


  zipkin:
    kafka.topic: user

and I tried to check the logs by accessing running docker container :

docker exec -it kafka-container /bin/sh

bin/kafka-console-consumer.sh --topic topic-name --bootstrap-server localhost:9092 --property print.headers=true

Still it does not work please let me know if I did mistake


Solution

  • We currently don't support any other sending mechanism than http. You can create a Sender bean yourself that would use Kafka. Please file an issue in Spring Boot that you're interested in adding different sender mechanisms