没有 Spring Cloud Sleuth 跟踪 Kafka

No Spring Cloud Sleuth traces over Kafka

我目前 运行正在 Spring Cloud Edgware.SR2。我正在将服务从 RabbitMQ 迁移到 Kafka,此时当我在 zipkin 主题上 运行 kafka-console-consumer.sh(即 kafka-console-consumer.sh --new-consumer --bootstrap-server localhost:9092 --topic zipkin --from-beginning)时,我没有看到任何 Zipkin 痕迹.结果,我当然没有在 Zipkin UI.

中看到任何跟踪信息

以下是我作为生产者服务的一部分所拥有的依赖项:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath></relativePath>
</parent>
<dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Edgware.SR2</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <version>1.5.9.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
      <scope>test</scope>
      <version>1.2.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-contract-verifier</artifactId>
      <scope>test</scope>
      <version>1.2.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
      <version>1.4.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-stream-kafka11</artifactId>
      <version>1.3.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.integration</groupId>
      <artifactId>spring-integration-core</artifactId>
      <version>4.3.13.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.integration</groupId>
      <artifactId>spring-integration-java-dsl</artifactId>
      <version>1.2.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.integration</groupId>
      <artifactId>spring-integration-jmx</artifactId>
      <version>4.3.13.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.integration</groupId>
      <artifactId>spring-integration-kafka</artifactId>
      <version>2.3.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.kafka</groupId>
      <artifactId>spring-kafka</artifactId>
      <version>1.3.2.RELEASE</version>
    </dependency>
    <dependency> 
       <groupId>org.springframework.cloud</groupId>
       <artifactId>spring-cloud-starter-zipkin</artifactId>
       <version>1.3.2.RELEASE</version>
   </dependency>
    <dependency>
      <groupId>org.springframework.restdocs</groupId>
      <artifactId>spring-restdocs-mockmvc</artifactId>
      <scope>test</scope>
      <version>2.0.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.security</groupId>
      <artifactId>spring-security-test</artifactId>
      <scope>test</scope>
      <version>4.2.3.RELEASE</version>
    </dependency>
  </dependencies>

这些是我在根据说明 at the bottom of the Spring Cloud Stream project page.

引入 spring-cloud-stream-binder-kafka11 依赖项后必须进行的依赖项覆盖

我还查看了 Sleuth with Zipkin via RabbitMQ or Kafka 的说明,我想我的那部分是正确的。

文档说明 If you want Sleuth over RabbitMQ add the spring-cloud-starter-zipkin and spring-rabbit dependencies. 它特别提到 RabbitMQ 需要 spring-cloud-starter-zipkin,但我添加了它,即使我使用的是 Kafka,因为没有这种依赖性它也无法工作。

关于我遗漏或配置不正确以捕获 Sleuth 踪迹并使用 Kafka 将它们发送到 Zipkin 服务器的任何想法?

为什么要手动设置依赖项的值?请使用 Edgware.SR2 BOM。您必须添加 kafka 依赖项,确保 rabbit 不在类路径中。如果类路径上同时有 kafka 和 rabbit,则需要设置 spring.zipkin.sender.type=kafka

更新:

正如我们在文档中所述,Sleuth Stream 支持在 Edgware 中已弃用,并在 FInchley 中删除。如果您决定采用使用本机 Zipkin 消息传递支持的新方法,那么您必须按照此处 https://github.com/openzipkin/zipkin/tree/master/zipkin-autoconfigure/collector-kafka10 所述将 Zipkin 服务器与 Kafka 一起使用。让我在这里复制部分文档


配置

以下配置点适用于 KAFKA_BOOTSTRAP_SERVERSzipkin.collector.kafka.bootstrap-servers 已设置。它们可以通过设置环境来配置 变量或通过使用 -Dproperty.name=value 命令行设置 java 系统 属性 争论。一些设置对应于"New Consumer Configs"中 Kafka documentation.

环境变量 | 属性 |新的消费者配置 |说明

KAFKA_BOOTSTRAP_SERVERS | zipkin.collector.kafka.bootstrap-servers | bootstrap.servers |以逗号分隔的经纪人列表,例如。 127.0.0.1:9092。无默认值

KAFKA_GROUP_ID | zipkin.collector.kafka.group-id | group.id |此进程代表的消费组。默认为 zipkin

KAFKA_TOPIC | zipkin.collector.kafka.topic | N/A |将使用 zipkin 跨越的主题的逗号分隔列表。默认为 zipkin

KAFKA_STREAMS | zipkin.collector.kafka.streams | N/A |使用主题的线程计数。默认为 1