Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Container object for {@link Span} and its corresponding {@link Tracer.SpanInScope}.
*
* @author Marcin Grzejszczak
* @author Arthur Gavlyukovskiy
* @since 3.1.0
*/
public class SpanAndScope implements Closeable {
Expand Down Expand Up @@ -58,7 +59,9 @@ public void close() {
if (log.isTraceEnabled()) {
log.trace("Closing span [" + this.span + "]");
}
this.scope.close();
if (this.scope != null) {
this.scope.close();
}
this.span.end();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.sql.CommonDataSource;

import net.ttddyy.dsproxy.listener.MethodExecutionListener;
import net.ttddyy.dsproxy.listener.QueryCountStrategy;
import net.ttddyy.dsproxy.listener.QueryExecutionListener;
Expand Down Expand Up @@ -100,7 +102,7 @@ DataSourceProxyDataSourceDecorator proxyDataSourceDecorator(
@Bean
TraceQueryExecutionListener traceQueryExecutionListener(Tracer tracer,
TraceJdbcProperties dataSourceDecoratorProperties,
ObjectProvider<List<TraceListenerStrategySpanCustomizer>> customizers) {
ObjectProvider<List<TraceListenerStrategySpanCustomizer<? super CommonDataSource>>> customizers) {
return new TraceQueryExecutionListener(tracer, dataSourceDecoratorProperties.getIncludes(),
customizers.getIfAvailable(ArrayList::new));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.ArrayList;
import java.util.List;

import javax.sql.CommonDataSource;

import com.p6spy.engine.event.JdbcEventListener;
import com.p6spy.engine.spy.DefaultJdbcEventListenerFactory;
import com.p6spy.engine.spy.JdbcEventListenerFactory;
Expand Down Expand Up @@ -56,7 +58,7 @@ static P6SpyPropertiesSetter p6SpyPropertiesSetter(ConfigurableApplicationContex
@ConditionalOnMissingBean
JdbcEventListenerFactory traceJdbcEventListenerFactory(ObjectProvider<List<JdbcEventListener>> listeners) {
JdbcEventListenerFactory jdbcEventListenerFactory = new DefaultJdbcEventListenerFactory();
List<JdbcEventListener> listenerList = listeners.getIfAvailable(() -> null);
List<JdbcEventListener> listenerList = listeners.getIfAvailable();
return listenerList != null ? new P6SpyContextJdbcEventListenerFactory(jdbcEventListenerFactory, listenerList)
: jdbcEventListenerFactory;
}
Expand All @@ -69,7 +71,7 @@ P6SpyDataSourceDecorator p6SpyDataSourceDecorator(JdbcEventListenerFactory jdbcE
@Bean
TraceJdbcEventListener tracingJdbcEventListener(Tracer tracer, DataSourceNameResolver dataSourceNameResolver,
TraceJdbcProperties traceJdbcProperties,
ObjectProvider<List<TraceListenerStrategySpanCustomizer>> customizers) {
ObjectProvider<List<TraceListenerStrategySpanCustomizer<? super CommonDataSource>>> customizers) {
return new TraceJdbcEventListener(tracer, dataSourceNameResolver, traceJdbcProperties.getIncludes(),
traceJdbcProperties.getP6spy().getTracing().isIncludeParameterValues(),
customizers.getIfAvailable(ArrayList::new));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.springframework.cloud.sleuth.instrument.jdbc.DataSourceDecorator;
import org.springframework.cloud.sleuth.instrument.jdbc.DataSourceNameResolver;
import org.springframework.cloud.sleuth.instrument.jdbc.TraceHikariListenerStrategySpanCustomizer;
import org.springframework.cloud.sleuth.instrument.jdbc.TraceListenerStrategySpanCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
Expand Down Expand Up @@ -65,7 +64,7 @@ DataSourceNameResolver traceDataSourceNameResolver() {

@Bean
@ConditionalOnClass(name = "com.zaxxer.hikari.HikariDataSource")
TraceListenerStrategySpanCustomizer hikariTraceListenerStrategySpanCustomizer() {
TraceHikariListenerStrategySpanCustomizer traceHikariListenerStrategySpanCustomizer() {
return new TraceHikariListenerStrategySpanCustomizer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class TraceJdbcEventListener extends SimpleJdbcEventListener implements O

public TraceJdbcEventListener(Tracer tracer, DataSourceNameResolver dataSourceNameResolver,
List<TraceType> traceTypes, boolean includeParameterValues,
List<TraceListenerStrategySpanCustomizer> customizers) {
List<TraceListenerStrategySpanCustomizer<? super CommonDataSource>> customizers) {
this.dataSourceNameResolver = dataSourceNameResolver;
this.includeParameterValues = includeParameterValues;
this.strategy = new TraceListenerStrategy<>(tracer, traceTypes, customizers);
Expand All @@ -67,15 +67,14 @@ public void onBeforeGetConnection(ConnectionInformation connectionInformation) {

@Override
public void onAfterGetConnection(ConnectionInformation connectionInformation, SQLException e) {
this.strategy.afterGetConnection(connectionInformation, connectionInformation.getConnection(), e);
CommonDataSource dataSource = connectionInformation.getDataSource();
String dataSourceName = this.dataSourceNameResolver.resolveDataSourceName(dataSource);
this.strategy.afterGetConnection(connectionInformation, connectionInformation.getConnection(), dataSourceName, e);
}

@Override
public void onBeforeAnyExecute(StatementInformation statementInformation) {
String dataSourceName = this.dataSourceNameResolver
.resolveDataSourceName(statementInformation.getConnectionInformation().getDataSource());
this.strategy.beforeQuery(statementInformation.getConnectionInformation(),
statementInformation.getConnectionInformation().getConnection(), statementInformation, dataSourceName);
this.strategy.beforeQuery(statementInformation.getConnectionInformation(), statementInformation);
}

@Override
Expand All @@ -86,11 +85,9 @@ public void onAfterAnyExecute(StatementInformation statementInformation, long ti

@Override
public void onBeforeResultSetNext(ResultSetInformation resultSetInformation) {
String dataSourceName = this.dataSourceNameResolver
.resolveDataSourceName(resultSetInformation.getConnectionInformation().getDataSource());
this.strategy.beforeResultSetNext(resultSetInformation.getConnectionInformation(),
resultSetInformation.getConnectionInformation().getConnection(),
resultSetInformation.getStatementInformation(), resultSetInformation, dataSourceName);
resultSetInformation.getStatementInformation(),
resultSetInformation);
}

@Override
Expand Down
Loading