【问题标题】:Sleuth not able to generate traces for JDBCTemplate accessSleuth 无法为 JDBCTemplate 访问生成跟踪
【发布时间】:2022-07-09 00:01:34
【问题描述】:

我正在探索在我们的应用程序中启用跟踪的 slueth。我在zipkin 中获得了API 到API 调用日志,但我没有记录任何其他JDBC 调用。我已在下面添加到我的application.yml

spring:
  sleuth:
    jdbc:
      # enable logging for datasource-proxy
      datasource-proxy:
        query:
          enable-logging: true

我也在下面添加到我的pom.xml

        <dependency>
            <groupId>net.ttddyy</groupId>
            <artifactId>datasource-proxy</artifactId>
            <version>${datasource-proxy.version}</version>
            <scope>runtime</scope>
        </dependency>

我是否错过了为 JDBC 模板启用 Zipkin 跟踪的内容?

【问题讨论】:

  • 这里有一个 Sleuth & Data 案例的示例 - github.com/spring-cloud-samples/spring-cloud-sleuth-samples/… 你能看看你的代码和示例有什么不同吗?
  • 这不适用于jdbcTemplate,它确实适用于 JPA 和所有项目。
  • 您能否创建一个复制此问题的示例并将其推送到 github?然后在 Spring Cloud Sleuth 中提出问题?

标签: spring-boot spring-data spring-cloud-sleuth zipkin


【解决方案1】:

现在我可以使用下面的方法解决这个问题

        <dependency>
            <groupId>com.github.gavlyukovskiy</groupId>
            <artifactId>datasource-proxy-spring-boot-starter</artifactId>
            <version>1.8.0</version>
        </dependency>

而不是添加侦探。我将很快研究一个最小的例子,看看为什么 Sleuth 不起作用

【讨论】:

    【解决方案2】:

    看来我也遇到了同样的问题。看起来像 TraceDataSourceDecoratorBeanPostProcessor.postProcessAfterInitialization() 被调用时

    Map<String, DataSourceDecorator> decorators = this.applicationContext
            .getBeansOfType(DataSourceDecorator.class).entrySet().stream()
     .sorted(Entry.comparingByValue(AnnotationAwareOrderComparator.INSTANCE))
    

    始终返回decorators 的空映射。

    另外,通过调试我看到了

    @ConditionalOnClass(P6DataSource.class)
    @ConditionalOnProperty(name = "spring.sleuth.jdbc.p6spy.enabled", havingValue = "true", matchIfMissing = true)
    class P6SpyConfiguration {
    
    ...
        
    @Bean
        P6SpyDataSourceDecorator p6SpyDataSourceDecorator(JdbcEventListenerFactory jdbcEventListenerFactory) {
            return new P6SpyDataSourceDecorator(jdbcEventListenerFactory);
        }
    
    }
    

    p6SpyDataSourceDecorator() bean 之后被调用/创建。对我来说,这似乎是一种竞争条件。我错过了什么吗?谢谢!

    使用:

      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-sleuth</artifactId>
        <version>3.2.1</version>
      </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin</artifactId>
            <version>3.2.1</version>
        </dependency>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      • 1970-01-01
      • 2022-07-01
      • 2017-09-28
      • 2021-12-30
      相关资源
      最近更新 更多