Detaching async traces only if tracing is still in progress

This commit is contained in:
Marcin Grzejszczak
2016-12-19 16:52:13 +01:00
parent a9139b57db
commit d2bf1ea776
3 changed files with 11 additions and 9 deletions

View File

@@ -45,6 +45,8 @@ public class TraceContinuingCallable<V> extends TraceCallable<V> implements Call
@Override
protected void close(Span span) {
getTracer().detach(span);
if (getTracer().isTracing()) {
getTracer().detach(span);
}
}
}

View File

@@ -19,6 +19,12 @@ package org.springframework.cloud.sleuth.instrument.hystrix;
import java.lang.invoke.MethodHandles;
import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.Tracer;
import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
@@ -26,12 +32,6 @@ import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.Tracer;
/**
* A {@link HystrixConcurrencyStrategy} that wraps a {@link Callable} in a
* {@link Callable} that either starts a new span or continues one if the tracing was
@@ -160,7 +160,7 @@ public class SleuthHystrixConcurrencyStrategy extends HystrixConcurrencyStrategy
}
this.tracer.close(span);
}
else {
else if(this.tracer.isTracing()) {
if (log.isDebugEnabled()) {
log.debug("Detaching span since it was continued " + span);
}

View File

@@ -129,7 +129,7 @@ class SleuthRxJavaSchedulersHook extends RxJavaSchedulersHook {
} finally {
if (created) {
this.tracer.close(span);
} else {
} else if (this.tracer.isTracing()) {
this.tracer.detach(span);
}
}