From c1325ba7281d1ed0b691e6f3f9160ac29e523d5c Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Wed, 30 Jan 2019 16:33:29 -0800 Subject: [PATCH 1/4] Add methods to set span operation when wrapping with a new trace --- .../java/com/palantir/tracing/Tracers.java | 71 ++++++++++++++----- .../com/palantir/tracing/TracersTest.java | 47 +++++++----- 2 files changed, 83 insertions(+), 35 deletions(-) diff --git a/tracing/src/main/java/com/palantir/tracing/Tracers.java b/tracing/src/main/java/com/palantir/tracing/Tracers.java index c5088aac4..661d4842f 100644 --- a/tracing/src/main/java/com/palantir/tracing/Tracers.java +++ b/tracing/src/main/java/com/palantir/tracing/Tracers.java @@ -104,52 +104,74 @@ public static Runnable wrap(Runnable delegate) { return new TracingAwareRunnable(delegate); } + /** + * Like {@link #wrapWithNewTrace(String, ExecutorService)}, but with a default initial span operation. + */ + public static ExecutorService wrapWithNewTrace(ExecutorService executorService) { + return wrapWithNewTrace(ROOT_SPAN_OPERATION, executorService); + } + /** * Wraps the provided executor service to make submitted tasks traceable with a fresh {@link Trace trace} - * for each execution, see {@link #wrapWithNewTrace(ExecutorService)}. This method should not be used to + * for each execution, see {@link #wrapWithNewTrace(String, ExecutorService)}. This method should not be used to * wrap a ScheduledExecutorService that has already been {@link #wrap(ExecutorService) wrapped}. If this is * done, a new trace will be generated for each execution, effectively bypassing the intent of the previous * wrapping. */ - public static ExecutorService wrapWithNewTrace(ExecutorService executorService) { + public static ExecutorService wrapWithNewTrace(String operation, ExecutorService executorService) { return new WrappingExecutorService(executorService) { @Override protected Callable wrapTask(Callable callable) { - return wrapWithNewTrace(callable); + return wrapWithNewTrace(operation, callable); } }; } /** - * Wraps the provided scheduled executor service to make submitted tasks traceable with a fresh {@link Trace trace} - * for each execution, see {@link #wrapWithNewTrace(ScheduledExecutorService)}. This method should not be used to - * wrap a ScheduledExecutorService that has already been {@link #wrap(ScheduledExecutorService) wrapped}. If this is - * done, a new trace will be generated for each execution, effectively bypassing the intent of the previous - * wrapping. + * Like {@link #wrapWithNewTrace(String, ScheduledExecutorService)}, but with a default initial span operation. */ public static ScheduledExecutorService wrapWithNewTrace(ScheduledExecutorService executorService) { + return wrapWithNewTrace(ROOT_SPAN_OPERATION, executorService); + } + + /** + * Wraps the provided scheduled executor service to make submitted tasks traceable with a fresh {@link Trace trace} + * for each execution, see {@link #wrapWithNewTrace(String, ScheduledExecutorService)}. This method should not be + * used to wrap a ScheduledExecutorService that has already been {@link #wrap(ScheduledExecutorService) wrapped}. + * If this is done, a new trace will be generated for each execution, effectively bypassing the intent of the + * previous wrapping. + */ + public static ScheduledExecutorService wrapWithNewTrace(String operation, + ScheduledExecutorService executorService) { return new WrappingScheduledExecutorService(executorService) { @Override protected Callable wrapTask(Callable callable) { - return wrapWithNewTrace(callable); + return wrapWithNewTrace(operation, callable); } }; } + /** + * Like {@link #wrapWithNewTrace(String, Callable)}, but with a default initial span operation. + */ + public static Callable wrapWithNewTrace(Callable delegate) { + return wrapWithNewTrace(ROOT_SPAN_OPERATION, delegate); + } + /** * Wraps the given {@link Callable} such that it creates a fresh {@link Trace tracing state} for its execution. * That is, the trace during its {@link Callable#call() execution} is entirely separate from the trace at * construction or any trace already set on the thread used to execute the callable. Each execution of the callable - * will have a fresh trace. + * will have a fresh trace. The given {@link String operation} is used to create the initial span. */ - public static Callable wrapWithNewTrace(Callable delegate) { + public static Callable wrapWithNewTrace(String operation, Callable delegate) { return () -> { // clear the existing trace and keep it around for restoration when we're done Optional originalTrace = Tracer.getAndClearTraceIfPresent(); try { Tracer.initTrace(Optional.empty(), Tracers.randomId()); - Tracer.startSpan(ROOT_SPAN_OPERATION); + Tracer.startSpan(operation); return delegate.call(); } finally { Tracer.fastCompleteSpan(); @@ -159,16 +181,23 @@ public static Callable wrapWithNewTrace(Callable delegate) { } /** - * Like {@link #wrapWithNewTrace(Callable)}, but for Runnables. + * Like {@link #wrapWithAlternateTraceId(String, Runnable)}, but with a default initial span operation. */ public static Runnable wrapWithNewTrace(Runnable delegate) { + return wrapWithNewTrace(ROOT_SPAN_OPERATION, delegate); + } + + /** + * Like {@link #wrapWithNewTrace(String, Callable)}, but for Runnables. + */ + public static Runnable wrapWithNewTrace(String operation, Runnable delegate) { return () -> { // clear the existing trace and keep it around for restoration when we're done Optional originalTrace = Tracer.getAndClearTraceIfPresent(); try { Tracer.initTrace(Optional.empty(), Tracers.randomId()); - Tracer.startSpan(ROOT_SPAN_OPERATION); + Tracer.startSpan(operation); delegate.run(); } finally { Tracer.fastCompleteSpan(); @@ -177,20 +206,28 @@ public static Runnable wrapWithNewTrace(Runnable delegate) { }; } + /** + * Like {@link #wrapWithAlternateTraceId(String, String, Runnable)}, but with a default initial span operation. + */ + public static Runnable wrapWithAlternateTraceId(String traceId, Runnable delegate) { + return wrapWithAlternateTraceId(traceId, ROOT_SPAN_OPERATION, delegate); + } + /** * Wraps the given {@link Runnable} such that it creates a fresh {@link Trace tracing state with the given traceId} * for its execution. That is, the trace during its {@link Runnable#run() execution} will use the traceId provided * instead of any trace already set on the thread used to execute the runnable. Each execution of the runnable - * will use a new {@link Trace tracing state} with the same given traceId. + * will use a new {@link Trace tracing state} with the same given traceId. The given {@link String operation} is + * used to create the initial span. */ - public static Runnable wrapWithAlternateTraceId(String traceId, Runnable delegate) { + public static Runnable wrapWithAlternateTraceId(String traceId, String operation, Runnable delegate) { return () -> { // clear the existing trace and keep it around for restoration when we're done Optional originalTrace = Tracer.getAndClearTraceIfPresent(); try { Tracer.initTrace(Optional.empty(), traceId); - Tracer.startSpan(ROOT_SPAN_OPERATION); + Tracer.startSpan(operation); delegate.run(); } finally { Tracer.fastCompleteSpan(); diff --git a/tracing/src/test/java/com/palantir/tracing/TracersTest.java b/tracing/src/test/java/com/palantir/tracing/TracersTest.java index 9fe24b310..7a89bce0c 100644 --- a/tracing/src/test/java/com/palantir/tracing/TracersTest.java +++ b/tracing/src/test/java/com/palantir/tracing/TracersTest.java @@ -95,11 +95,12 @@ public void testScheduledExecutorServiceWrapsCallables() throws Exception { @Test public void testScheduledExecutorServiceWrapsCallablesWithNewTraces() throws Exception { + String someOperartion = "operationToUse"; ScheduledExecutorService wrappedService = - Tracers.wrapWithNewTrace(Executors.newSingleThreadScheduledExecutor()); + Tracers.wrapWithNewTrace(someOperartion, Executors.newSingleThreadScheduledExecutor()); - Callable callable = newTraceExpectingCallable(); - Runnable runnable = newTraceExpectingRunnable(); + Callable callable = newTraceExpectingCallable(someOperartion); + Runnable runnable = newTraceExpectingRunnable(someOperartion); // Empty trace wrappedService.schedule(callable, 0, TimeUnit.SECONDS).get(); @@ -121,11 +122,12 @@ public void testScheduledExecutorServiceWrapsCallablesWithNewTraces() throws Exc @Test public void testExecutorServiceWrapsCallablesWithNewTraces() throws Exception { + String someOperartion = "operationToUse"; ExecutorService wrappedService = - Tracers.wrapWithNewTrace(Executors.newSingleThreadExecutor()); + Tracers.wrapWithNewTrace(someOperartion, Executors.newSingleThreadExecutor()); - Callable callable = newTraceExpectingCallable(); - Runnable runnable = newTraceExpectingRunnable(); + Callable callable = newTraceExpectingCallable(someOperartion); + Runnable runnable = newTraceExpectingRunnable(someOperartion); // Empty trace wrappedService.submit(callable).get(); @@ -227,7 +229,8 @@ public void testWrapCallableWithNewTrace_traceStateInsideCallableIsIsolated() th @Test public void testWrapCallableWithNewTrace_traceStateInsideCallableHasSpan() throws Exception { - Callable> wrappedCallable = Tracers.wrapWithNewTrace(() -> { + String operationToUse = "someOperation"; + Callable> wrappedCallable = Tracers.wrapWithNewTrace(operationToUse, () -> { return getCurrentFullTrace(); }); @@ -237,7 +240,7 @@ public void testWrapCallableWithNewTrace_traceStateInsideCallableHasSpan() throw OpenSpan span = spans.get(0); - assertThat(span.getOperation()).isEqualTo("root"); + assertThat(span.getOperation()).isEqualTo(operationToUse); assertThat(span.getParentSpanId()).isEmpty(); } @@ -297,7 +300,8 @@ public void testWrapRunnableWithNewTrace_traceStateInsideRunnableIsIsolated() th public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasSpan() throws Exception { List> spans = Lists.newArrayList(); - Runnable wrappedRunnable = Tracers.wrapWithNewTrace(() -> { + String operationToUse = "someOperation"; + Runnable wrappedRunnable = Tracers.wrapWithNewTrace(operationToUse, () -> { spans.add(getCurrentFullTrace()); }); @@ -307,12 +311,12 @@ public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasSpan() throw OpenSpan span = spans.get(0).get(0); - assertThat(span.getOperation()).isEqualTo("root"); + assertThat(span.getOperation()).isEqualTo(operationToUse); assertThat(span.getParentSpanId()).isEmpty(); } @Test - public void testWrapRunnableWithNewTrace_traceStateRestoredWhenThrows() throws Exception { + public void testWrapRunnableWithNewTrace_traceStateRestoredWhenThrows() { String traceIdBeforeConstruction = Tracer.getTraceId(); Runnable rawRunnable = () -> { @@ -357,11 +361,12 @@ public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableUsesGiv } @Test - public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasSpan() throws Exception { + public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasSpan() { List> spans = Lists.newArrayList(); String traceIdToUse = "someTraceId"; - Runnable wrappedRunnable = Tracers.wrapWithAlternateTraceId(traceIdToUse, () -> { + String operationToUse = "someOperation"; + Runnable wrappedRunnable = Tracers.wrapWithAlternateTraceId(traceIdToUse, operationToUse, () -> { spans.add(getCurrentFullTrace()); }); @@ -371,7 +376,7 @@ public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasSpan OpenSpan span = spans.get(0).get(0); - assertThat(span.getOperation()).isEqualTo("root"); + assertThat(span.getOperation()).isEqualTo(operationToUse); assertThat(span.getParentSpanId()).isEmpty(); } @@ -406,7 +411,7 @@ public void testTraceIdGeneration() throws Exception { assertThat(Tracers.longToPaddedHex(123456789L)).isEqualTo("00000000075bcd15"); } - private static Callable newTraceExpectingCallable() { + private static Callable newTraceExpectingCallable(String expectedOperation) { final Set seenTraceIds = new HashSet<>(); seenTraceIds.add(Tracer.getTraceId()); @@ -414,17 +419,20 @@ private static Callable newTraceExpectingCallable() { @Override public Void call() throws Exception { String newTraceId = Tracer.getTraceId(); + List spans = getCurrentFullTrace(); assertThat(MDC.get(Tracers.TRACE_ID_KEY)).isEqualTo(newTraceId); assertThat(seenTraceIds).doesNotContain(newTraceId); - assertThat(getCurrentFullTrace()).hasSize(1); + assertThat(spans).hasSize(1); + assertThat(spans.get(0).getOperation()).isEqualTo(expectedOperation); + assertThat(spans.get(0).getParentSpanId()).isEmpty(); seenTraceIds.add(newTraceId); return null; } }; } - private static Runnable newTraceExpectingRunnable() { + private static Runnable newTraceExpectingRunnable(String expectedOperation) { final Set seenTraceIds = new HashSet<>(); seenTraceIds.add(Tracer.getTraceId()); @@ -432,10 +440,13 @@ private static Runnable newTraceExpectingRunnable() { @Override public void run() { String newTraceId = Tracer.getTraceId(); + List spans = getCurrentFullTrace(); assertThat(MDC.get(Tracers.TRACE_ID_KEY)).isEqualTo(newTraceId); assertThat(seenTraceIds).doesNotContain(newTraceId); - assertThat(getCurrentFullTrace()).hasSize(1); + assertThat(spans).hasSize(1); + assertThat(spans.get(0).getOperation()).isEqualTo(expectedOperation); + assertThat(spans.get(0).getParentSpanId()).isEmpty(); seenTraceIds.add(newTraceId); } }; From 202b3bd852171a3506d9f80d7c3678f695273ef3 Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Wed, 30 Jan 2019 16:33:46 -0800 Subject: [PATCH 2/4] Tests --- .../com/palantir/tracing/TracersTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tracing/src/test/java/com/palantir/tracing/TracersTest.java b/tracing/src/test/java/com/palantir/tracing/TracersTest.java index 7a89bce0c..58bb68fd1 100644 --- a/tracing/src/test/java/com/palantir/tracing/TracersTest.java +++ b/tracing/src/test/java/com/palantir/tracing/TracersTest.java @@ -229,6 +229,22 @@ public void testWrapCallableWithNewTrace_traceStateInsideCallableIsIsolated() th @Test public void testWrapCallableWithNewTrace_traceStateInsideCallableHasSpan() throws Exception { + Callable> wrappedCallable = Tracers.wrapWithNewTrace(() -> { + return getCurrentFullTrace(); + }); + + List spans = wrappedCallable.call(); + + assertThat(spans).hasSize(1); + + OpenSpan span = spans.get(0); + + assertThat(span.getOperation()).isEqualTo("root"); + assertThat(span.getParentSpanId()).isEmpty(); + } + + @Test + public void testWrapCallableWithNewTrace_traceStateInsideCallableHasGivenSpan() throws Exception { String operationToUse = "someOperation"; Callable> wrappedCallable = Tracers.wrapWithNewTrace(operationToUse, () -> { return getCurrentFullTrace(); @@ -300,6 +316,24 @@ public void testWrapRunnableWithNewTrace_traceStateInsideRunnableIsIsolated() th public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasSpan() throws Exception { List> spans = Lists.newArrayList(); + Runnable wrappedRunnable = Tracers.wrapWithNewTrace(() -> { + spans.add(getCurrentFullTrace()); + }); + + wrappedRunnable.run(); + + assertThat(spans.get(0)).hasSize(1); + + OpenSpan span = spans.get(0).get(0); + + assertThat(span.getOperation()).isEqualTo("root"); + assertThat(span.getParentSpanId()).isEmpty(); + } + + @Test + public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasGivenSpan() throws Exception { + List> spans = Lists.newArrayList(); + String operationToUse = "someOperation"; Runnable wrappedRunnable = Tracers.wrapWithNewTrace(operationToUse, () -> { spans.add(getCurrentFullTrace()); @@ -364,6 +398,25 @@ public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableUsesGiv public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasSpan() { List> spans = Lists.newArrayList(); + String traceIdToUse = "someTraceId"; + Runnable wrappedRunnable = Tracers.wrapWithAlternateTraceId(traceIdToUse, () -> { + spans.add(getCurrentFullTrace()); + }); + + wrappedRunnable.run(); + + assertThat(spans.get(0)).hasSize(1); + + OpenSpan span = spans.get(0).get(0); + + assertThat(span.getOperation()).isEqualTo("root"); + assertThat(span.getParentSpanId()).isEmpty(); + } + + @Test + public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasGivenSpan() { + List> spans = Lists.newArrayList(); + String traceIdToUse = "someTraceId"; String operationToUse = "someOperation"; Runnable wrappedRunnable = Tracers.wrapWithAlternateTraceId(traceIdToUse, operationToUse, () -> { From 71665e399dcd86a87432ae96df3c95c56f0e91ba Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Fri, 1 Feb 2019 11:18:24 -0800 Subject: [PATCH 3/4] Typo --- .../java/com/palantir/tracing/TracersTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tracing/src/test/java/com/palantir/tracing/TracersTest.java b/tracing/src/test/java/com/palantir/tracing/TracersTest.java index 58bb68fd1..18f7ff4a1 100644 --- a/tracing/src/test/java/com/palantir/tracing/TracersTest.java +++ b/tracing/src/test/java/com/palantir/tracing/TracersTest.java @@ -95,12 +95,12 @@ public void testScheduledExecutorServiceWrapsCallables() throws Exception { @Test public void testScheduledExecutorServiceWrapsCallablesWithNewTraces() throws Exception { - String someOperartion = "operationToUse"; + String someOperation = "operationToUse"; ScheduledExecutorService wrappedService = - Tracers.wrapWithNewTrace(someOperartion, Executors.newSingleThreadScheduledExecutor()); + Tracers.wrapWithNewTrace(someOperation, Executors.newSingleThreadScheduledExecutor()); - Callable callable = newTraceExpectingCallable(someOperartion); - Runnable runnable = newTraceExpectingRunnable(someOperartion); + Callable callable = newTraceExpectingCallable(someOperation); + Runnable runnable = newTraceExpectingRunnable(someOperation); // Empty trace wrappedService.schedule(callable, 0, TimeUnit.SECONDS).get(); @@ -122,12 +122,12 @@ public void testScheduledExecutorServiceWrapsCallablesWithNewTraces() throws Exc @Test public void testExecutorServiceWrapsCallablesWithNewTraces() throws Exception { - String someOperartion = "operationToUse"; + String someOperation = "operationToUse"; ExecutorService wrappedService = - Tracers.wrapWithNewTrace(someOperartion, Executors.newSingleThreadExecutor()); + Tracers.wrapWithNewTrace(someOperation, Executors.newSingleThreadExecutor()); - Callable callable = newTraceExpectingCallable(someOperartion); - Runnable runnable = newTraceExpectingRunnable(someOperartion); + Callable callable = newTraceExpectingCallable(someOperation); + Runnable runnable = newTraceExpectingRunnable(someOperation); // Empty trace wrappedService.submit(callable).get(); From b74eade1ce10813c7fcb4e31e5b80975f18d83cc Mon Sep 17 00:00:00 2001 From: Patrick Koenig Date: Fri, 1 Feb 2019 15:59:49 -0800 Subject: [PATCH 4/4] CompileTimeConstant --- .../java/com/palantir/tracing/Tracers.java | 17 ++++++----- .../com/palantir/tracing/TracersTest.java | 29 ++++++++----------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/tracing/src/main/java/com/palantir/tracing/Tracers.java b/tracing/src/main/java/com/palantir/tracing/Tracers.java index 661d4842f..d7e246d97 100644 --- a/tracing/src/main/java/com/palantir/tracing/Tracers.java +++ b/tracing/src/main/java/com/palantir/tracing/Tracers.java @@ -16,6 +16,7 @@ package com.palantir.tracing; +import com.google.errorprone.annotations.CompileTimeConstant; import java.util.Optional; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; @@ -116,9 +117,10 @@ public static ExecutorService wrapWithNewTrace(ExecutorService executorService) * for each execution, see {@link #wrapWithNewTrace(String, ExecutorService)}. This method should not be used to * wrap a ScheduledExecutorService that has already been {@link #wrap(ExecutorService) wrapped}. If this is * done, a new trace will be generated for each execution, effectively bypassing the intent of the previous - * wrapping. + * wrapping. The given {@link String operation} is used to create the initial span. */ - public static ExecutorService wrapWithNewTrace(String operation, ExecutorService executorService) { + public static ExecutorService wrapWithNewTrace(@CompileTimeConstant String operation, + ExecutorService executorService) { return new WrappingExecutorService(executorService) { @Override protected Callable wrapTask(Callable callable) { @@ -139,9 +141,9 @@ public static ScheduledExecutorService wrapWithNewTrace(ScheduledExecutorService * for each execution, see {@link #wrapWithNewTrace(String, ScheduledExecutorService)}. This method should not be * used to wrap a ScheduledExecutorService that has already been {@link #wrap(ScheduledExecutorService) wrapped}. * If this is done, a new trace will be generated for each execution, effectively bypassing the intent of the - * previous wrapping. + * previous wrapping. The given {@link String operation} is used to create the initial span. */ - public static ScheduledExecutorService wrapWithNewTrace(String operation, + public static ScheduledExecutorService wrapWithNewTrace(@CompileTimeConstant String operation, ScheduledExecutorService executorService) { return new WrappingScheduledExecutorService(executorService) { @Override @@ -164,7 +166,7 @@ public static Callable wrapWithNewTrace(Callable delegate) { * construction or any trace already set on the thread used to execute the callable. Each execution of the callable * will have a fresh trace. The given {@link String operation} is used to create the initial span. */ - public static Callable wrapWithNewTrace(String operation, Callable delegate) { + public static Callable wrapWithNewTrace(@CompileTimeConstant String operation, Callable delegate) { return () -> { // clear the existing trace and keep it around for restoration when we're done Optional originalTrace = Tracer.getAndClearTraceIfPresent(); @@ -190,7 +192,7 @@ public static Runnable wrapWithNewTrace(Runnable delegate) { /** * Like {@link #wrapWithNewTrace(String, Callable)}, but for Runnables. */ - public static Runnable wrapWithNewTrace(String operation, Runnable delegate) { + public static Runnable wrapWithNewTrace(@CompileTimeConstant String operation, Runnable delegate) { return () -> { // clear the existing trace and keep it around for restoration when we're done Optional originalTrace = Tracer.getAndClearTraceIfPresent(); @@ -220,7 +222,8 @@ public static Runnable wrapWithAlternateTraceId(String traceId, Runnable delegat * will use a new {@link Trace tracing state} with the same given traceId. The given {@link String operation} is * used to create the initial span. */ - public static Runnable wrapWithAlternateTraceId(String traceId, String operation, Runnable delegate) { + public static Runnable wrapWithAlternateTraceId(String traceId, @CompileTimeConstant String operation, Runnable + delegate) { return () -> { // clear the existing trace and keep it around for restoration when we're done Optional originalTrace = Tracer.getAndClearTraceIfPresent(); diff --git a/tracing/src/test/java/com/palantir/tracing/TracersTest.java b/tracing/src/test/java/com/palantir/tracing/TracersTest.java index 18f7ff4a1..0b636a40a 100644 --- a/tracing/src/test/java/com/palantir/tracing/TracersTest.java +++ b/tracing/src/test/java/com/palantir/tracing/TracersTest.java @@ -95,12 +95,11 @@ public void testScheduledExecutorServiceWrapsCallables() throws Exception { @Test public void testScheduledExecutorServiceWrapsCallablesWithNewTraces() throws Exception { - String someOperation = "operationToUse"; ScheduledExecutorService wrappedService = - Tracers.wrapWithNewTrace(someOperation, Executors.newSingleThreadScheduledExecutor()); + Tracers.wrapWithNewTrace("operationToUse", Executors.newSingleThreadScheduledExecutor()); - Callable callable = newTraceExpectingCallable(someOperation); - Runnable runnable = newTraceExpectingRunnable(someOperation); + Callable callable = newTraceExpectingCallable("operationToUse"); + Runnable runnable = newTraceExpectingRunnable("operationToUse"); // Empty trace wrappedService.schedule(callable, 0, TimeUnit.SECONDS).get(); @@ -122,12 +121,11 @@ public void testScheduledExecutorServiceWrapsCallablesWithNewTraces() throws Exc @Test public void testExecutorServiceWrapsCallablesWithNewTraces() throws Exception { - String someOperation = "operationToUse"; ExecutorService wrappedService = - Tracers.wrapWithNewTrace(someOperation, Executors.newSingleThreadExecutor()); + Tracers.wrapWithNewTrace("operationToUse", Executors.newSingleThreadExecutor()); - Callable callable = newTraceExpectingCallable(someOperation); - Runnable runnable = newTraceExpectingRunnable(someOperation); + Callable callable = newTraceExpectingCallable("operationToUse"); + Runnable runnable = newTraceExpectingRunnable("operationToUse"); // Empty trace wrappedService.submit(callable).get(); @@ -245,8 +243,7 @@ public void testWrapCallableWithNewTrace_traceStateInsideCallableHasSpan() throw @Test public void testWrapCallableWithNewTrace_traceStateInsideCallableHasGivenSpan() throws Exception { - String operationToUse = "someOperation"; - Callable> wrappedCallable = Tracers.wrapWithNewTrace(operationToUse, () -> { + Callable> wrappedCallable = Tracers.wrapWithNewTrace("someOperation", () -> { return getCurrentFullTrace(); }); @@ -256,7 +253,7 @@ public void testWrapCallableWithNewTrace_traceStateInsideCallableHasGivenSpan() OpenSpan span = spans.get(0); - assertThat(span.getOperation()).isEqualTo(operationToUse); + assertThat(span.getOperation()).isEqualTo("someOperation"); assertThat(span.getParentSpanId()).isEmpty(); } @@ -334,8 +331,7 @@ public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasSpan() throw public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasGivenSpan() throws Exception { List> spans = Lists.newArrayList(); - String operationToUse = "someOperation"; - Runnable wrappedRunnable = Tracers.wrapWithNewTrace(operationToUse, () -> { + Runnable wrappedRunnable = Tracers.wrapWithNewTrace("someOperation", () -> { spans.add(getCurrentFullTrace()); }); @@ -345,7 +341,7 @@ public void testWrapRunnableWithNewTrace_traceStateInsideRunnableHasGivenSpan() OpenSpan span = spans.get(0).get(0); - assertThat(span.getOperation()).isEqualTo(operationToUse); + assertThat(span.getOperation()).isEqualTo("someOperation"); assertThat(span.getParentSpanId()).isEmpty(); } @@ -418,8 +414,7 @@ public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasGive List> spans = Lists.newArrayList(); String traceIdToUse = "someTraceId"; - String operationToUse = "someOperation"; - Runnable wrappedRunnable = Tracers.wrapWithAlternateTraceId(traceIdToUse, operationToUse, () -> { + Runnable wrappedRunnable = Tracers.wrapWithAlternateTraceId(traceIdToUse, "someOperation", () -> { spans.add(getCurrentFullTrace()); }); @@ -429,7 +424,7 @@ public void testWrapRunnableWithAlternateTraceId_traceStateInsideRunnableHasGive OpenSpan span = spans.get(0).get(0); - assertThat(span.getOperation()).isEqualTo(operationToUse); + assertThat(span.getOperation()).isEqualTo("someOperation"); assertThat(span.getParentSpanId()).isEmpty(); }