spring-cloud/spring-cloud-sleuth

sleuth-3.1.9+datasource-proxy-1.10+flowable-6.8.0 Unable to start the springboot project properly

845146913 opened this issue · 1 comments

DataSourceProxy + Sleuth Unable to work

The project uses springboot 2.7.X, spring cloud 2021.0.8 (sleuth-3.1.9), flowable-spring-boot-starter-process-6.8.0, mybatis-plus-boot-starter-3.5.3.2,datasource-proxy-1.10. I want to enable the slow query feature of sleuth, with the following configuration:

  1. pom.xml
<dependencies>
      <dependency>
            <groupId>net.ttddyy</groupId>
            <artifactId>datasource-proxy</artifactId>
            <version>1.10</version>
            <scope>runtime</scope>
        </dependency>
       <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter-process</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
        </dependency>
</dependencies>
  1. application.yml
spring.sleuth:
  jdbc:
    datasource-proxy:
      slow-query:
        enable-logging: true
        threshold: 10
      query:
        enable-logging: true

The error report is as follows:

Caused by: org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is net.ttddyy.dsproxy.DataSourceProxyException: Failed to perform getConnection
	at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:313)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:137)
	at org.flowable.common.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:57)
	at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
	at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56)
	at org.flowable.eventregistry.impl.EventRegistryEngineImpl.<init>(EventRegistryEngineImpl.java:47)
	at org.flowable.eventregistry.impl.EventRegistryEngineConfiguration.buildEventRegistryEngine(EventRegistryEngineConfiguration.java:208)
	at org.flowable.eventregistry.spring.SpringEventRegistryEngineConfiguration.buildEventRegistryEngine(SpringEventRegistryEngineConfiguration.java:73)
	at org.flowable.eventregistry.spring.configurator.SpringEventRegistryConfigurator.initEventRegistryEngine(SpringEventRegistryConfigurator.java:57)
	at org.flowable.eventregistry.spring.configurator.SpringEventRegistryConfigurator.configure(SpringEventRegistryConfigurator.java:47)
	at org.flowable.common.engine.impl.AbstractEngineConfiguration.configuratorsAfterInit(AbstractEngineConfiguration.java:1120)
	at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:1022)
	at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:906)
	at org.flowable.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:76)
	at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:59)
	at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169)
	... 147 more
Caused by: net.ttddyy.dsproxy.DataSourceProxyException: Failed to perform getConnection
	at net.ttddyy.dsproxy.support.ProxyDataSource.getConnectionProxy(ProxyDataSource.java:88)
	at net.ttddyy.dsproxy.support.ProxyDataSource.getConnection(ProxyDataSource.java:73)
	at com.p6spy.engine.spy.P6DataSource.getConnection(P6DataSource.java:300)
	at org.springframework.jdbc.datasource.DelegatingDataSource.getConnection(DelegatingDataSource.java:99)
	at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:269)
	... 165 more
Caused by: java.lang.NullPointerException: Cannot invoke "net.ttddyy.dsproxy.ConnectionInfo.getConnectionId()" because the return value of "net.ttddyy.dsproxy.listener.MethodExecutionContext.getConnectionInfo()" is null
	at org.springframework.cloud.sleuth.instrument.jdbc.TraceQueryExecutionListener.beforeMethod(TraceQueryExecutionListener.java:77)
	at net.ttddyy.dsproxy.listener.CompositeMethodListener.beforeMethod(CompositeMethodListener.java:18)
	at net.ttddyy.dsproxy.proxy.ProxyLogicSupport.proceedMethodExecution(ProxyLogicSupport.java:93)
	at net.ttddyy.dsproxy.support.ProxyDataSource.getConnectionProxy(ProxyDataSource.java:83)
	... 169 more

Through debugging the source code(org.springframework.cloud.sleuth.instrument.jdbc.TraceQueryExecutionListener), it was found that:

public class TraceQueryExecutionListener implements QueryExecutionListener, MethodExecutionListener, Ordered {
   @Override
	public void beforeMethod(MethodExecutionContext executionContext) {
		Object target = executionContext.getTarget();
		String methodName = executionContext.getMethod().getName();
		String dataSourceName = executionContext.getProxyConfig().getDataSourceName();
               // the executionContext.getConnectionInfo() method returned null,resulting in a java.lang.NullPointerException
		String connectionId = executionContext.getConnectionInfo().getConnectionId();
		if (target instanceof DataSource && methodName.equals("getConnection")) {
			DataSource dataSource = (DataSource) target;
			this.strategy.beforeGetConnection(connectionId, dataSource, dataSourceName);
		}
		else if (target instanceof ResultSet) {
			ResultSet resultSet = (ResultSet) target;
			if (methodName.equals("next")) {
				try {
					this.strategy.beforeResultSetNext(connectionId, resultSet.getStatement(), resultSet);
				}
				catch (SQLException ignore) {
				}
			}
		}
	}
}

image

May I ask how to handle this issue? thx

Sleuth reached the end of its OSS support timeline. We encourage to migrate to Micrometer Tracing that fixes issues that Sleuth had.