Rename ContextPropagator to TraceScope

This commit is contained in:
Andrew Kent 2018-03-12 10:24:43 -07:00
parent 45aff57740
commit 428e304164
4 changed files with 25 additions and 24 deletions

View File

@ -70,6 +70,7 @@ class ExecutorInstrumentationTest extends Specification {
trace.size() == 2
trace.get(0).operationName == "parent"
trace.get(1).operationName == "asyncChild"
trace.get(1).parentId == trace.get(0).spanId
cleanup:
pool?.shutdown()

View File

@ -11,7 +11,7 @@ import com.google.auto.service.AutoService;
import datadog.trace.agent.tooling.DDAdvice;
import datadog.trace.agent.tooling.HelperInjector;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.context.ContextPropagator;
import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.util.GlobalTracer;
import java.lang.reflect.Field;
@ -137,8 +137,8 @@ public final class ExecutorInstrumentation extends Instrumenter.Configurable {
public static DatadogWrapper wrapJob(
@Advice.Argument(value = 0, readOnly = false) Runnable task) {
final Scope scope = GlobalTracer.get().scopeManager().active();
if (scope instanceof ContextPropagator && task != null && !(task instanceof DatadogWrapper)) {
task = new RunnableWrapper(task, (ContextPropagator) scope);
if (scope instanceof TraceScope && task != null && !(task instanceof DatadogWrapper)) {
task = new RunnableWrapper(task, (TraceScope) scope);
return (DatadogWrapper) task;
}
return null;
@ -158,8 +158,8 @@ public final class ExecutorInstrumentation extends Instrumenter.Configurable {
public static DatadogWrapper wrapJob(
@Advice.Argument(value = 0, readOnly = false) Callable task) {
final Scope scope = GlobalTracer.get().scopeManager().active();
if (scope instanceof ContextPropagator && task != null && !(task instanceof DatadogWrapper)) {
task = new CallableWrapper(task, (ContextPropagator) scope);
if (scope instanceof TraceScope && task != null && !(task instanceof DatadogWrapper)) {
task = new CallableWrapper(task, (TraceScope) scope);
return (DatadogWrapper) task;
}
return null;
@ -179,12 +179,12 @@ public final class ExecutorInstrumentation extends Instrumenter.Configurable {
public static Collection<?> wrapJob(
@Advice.Argument(value = 0, readOnly = false) Collection<? extends Callable<?>> tasks) {
final Scope scope = GlobalTracer.get().scopeManager().active();
if (scope instanceof ContextPropagator) {
if (scope instanceof TraceScope) {
Collection<Callable<?>> wrappedTasks = new ArrayList<>(tasks.size());
for (Callable task : tasks) {
if (task != null) {
if (!(task instanceof CallableWrapper)) {
task = new CallableWrapper(task, (ContextPropagator) scope);
task = new CallableWrapper(task, (TraceScope) scope);
}
wrappedTasks.add(task);
}
@ -211,9 +211,9 @@ public final class ExecutorInstrumentation extends Instrumenter.Configurable {
/** Marker interface for tasks which are wrapped to propagate the trace context. */
@Slf4j
public abstract static class DatadogWrapper {
protected final ContextPropagator.Continuation continuation;
protected final TraceScope.Continuation continuation;
public DatadogWrapper(ContextPropagator scope) {
public DatadogWrapper(TraceScope scope) {
continuation = scope.capture(true);
log.debug("created continuation {} from scope {}", continuation, scope);
}
@ -230,14 +230,14 @@ public final class ExecutorInstrumentation extends Instrumenter.Configurable {
public static class RunnableWrapper extends DatadogWrapper implements Runnable {
private final Runnable delegatee;
public RunnableWrapper(Runnable toWrap, ContextPropagator scope) {
public RunnableWrapper(Runnable toWrap, TraceScope scope) {
super(scope);
delegatee = toWrap;
}
@Override
public void run() {
final ContextPropagator context = continuation.activate();
final TraceScope context = continuation.activate();
try {
delegatee.run();
} finally {
@ -250,14 +250,14 @@ public final class ExecutorInstrumentation extends Instrumenter.Configurable {
public static class CallableWrapper<T> extends DatadogWrapper implements Callable<T> {
private final Callable<T> delegatee;
public CallableWrapper(Callable<T> toWrap, ContextPropagator scope) {
public CallableWrapper(Callable<T> toWrap, TraceScope scope) {
super(scope);
delegatee = toWrap;
}
@Override
public T call() throws Exception {
final ContextPropagator context = continuation.activate();
final TraceScope context = continuation.activate();
try {
return delegatee.call();
} finally {

View File

@ -1,10 +1,10 @@
package datadog.trace.context;
/** An object when can propagate a datadog trace across multiple threads. */
public interface ContextPropagator {
public interface TraceScope {
/**
* Prevent the trace attached to this ContextPropagator from reporting until the returned
* Continuation finishes.
* Prevent the trace attached to this TraceScope from reporting until the returned Continuation
* finishes.
*
* <p>Should be called on the parent thread.
*/
@ -20,6 +20,6 @@ public interface ContextPropagator {
*
* <p>Should be called on the child thread.
*/
ContextPropagator activate();
TraceScope activate();
}
}

View File

@ -2,7 +2,7 @@ package datadog.opentracing.scopemanager;
import datadog.opentracing.DDSpanContext;
import datadog.opentracing.PendingTrace;
import datadog.trace.context.ContextPropagator;
import datadog.trace.context.TraceScope;
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.noop.NoopScopeManager;
@ -13,7 +13,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ContinuableScope implements Scope, ContextPropagator {
public class ContinuableScope implements Scope, TraceScope {
final ContextualScopeManager scopeManager;
final AtomicInteger refCount;
private final Span wrapped;
@ -67,7 +67,7 @@ public class ContinuableScope implements Scope, ContextPropagator {
return new Continuation(this.finishOnClose && finishOnClose);
}
public class Continuation implements Closeable, ContextPropagator.Continuation {
public class Continuation implements Closeable, TraceScope.Continuation {
public WeakReference<Continuation> ref;
private final AtomicBoolean used = new AtomicBoolean(false);
@ -109,7 +109,7 @@ public class ContinuableScope implements Scope, ContextPropagator {
}
}
private class ClosingScope implements Scope, ContextPropagator {
private class ClosingScope implements Scope, TraceScope {
private final Scope wrappedScope;
private ClosingScope(final Scope wrappedScope) {
@ -118,11 +118,11 @@ public class ContinuableScope implements Scope, ContextPropagator {
@Override
public Continuation capture(boolean finishOnClose) {
if (wrappedScope instanceof ContextPropagator) {
return ((ContextPropagator) wrappedScope).capture(finishOnClose);
if (wrappedScope instanceof TraceScope) {
return ((TraceScope) wrappedScope).capture(finishOnClose);
} else {
log.debug(
"{} Failed to capture. ClosingScope does not wrap a ContextPropagator: {}.",
"{} Failed to capture. ClosingScope does not wrap a TraceScope: {}.",
this,
wrappedScope);
return null;