Issue
JDBC Sleuth instrumentation is not taking place
Root Cause
Datasource bean is created before the p6SpyDataSourceDecorator bean creation.
Analysis
Looks like when TraceDataSourceDecoratorBeanPostProcessor.postProcessAfterInitialization() is called
Map<String, DataSourceDecorator> decorators = this.applicationContext
.getBeansOfType(DataSourceDecorator.class).entrySet().stream()
.sorted(Entry.comparingByValue(AnnotationAwareOrderComparator.INSTANCE))
always return an empty map of decorators, when called on my HikariDataSource.
Also, in my case this was because the HikariDataSource was created before the p6SpyDataSourceDecorator was created. This had as a result the decorators to be empty and as a consequence the HikariDataSource not to be instrumented.
It seems Spring auto configuration has a bug.
Work Around
My work around is the following and now I have proper instrumentation:
@Primary
@Bean
@DependsOn("p6SpyDataSourceDecorator")
@ConfigurationProperties(prefix = "spring.datasource.hikari")
HikariDataSource dataSource(DataSourceProperties properties) {
HikariDataSource dataSource = createDataSource(properties, HikariDataSource.class);
if (StringUtils.hasText(properties.getName())) {
dataSource.setPoolName(properties.getName());
}
return dataSource;
}
Issues with Work Around
The downside is that I had to allow circular dependencies.
Versions
<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>
Comment From: wilkinsona
Spring Cloud Sleuth is managed as a separate project https://github.com/spring-cloud/spring-cloud-sleuth. Unfortunately, we can't transfer GitHub issues between organisations. Please open an issue in the Spring Cloud Sleuth repository.