From 830dadc0bd827ab965699bcba015f50b745d7750 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Tue, 12 Jan 2021 17:34:16 +0000 Subject: [PATCH 1/2] Update to OpenTracing 0.33 --- .../tracing/TracingContextProvider.java | 39 ++++++++++--------- pom.xml | 2 +- .../TracingContextPropagationTest.java | 11 +++++- .../TracingContextPropagationStressTest.java | 6 ++- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/implementation/tracing-propagation/src/main/java/io/smallrye/faulttolerance/tracing/TracingContextProvider.java b/implementation/tracing-propagation/src/main/java/io/smallrye/faulttolerance/tracing/TracingContextProvider.java index 8b9b068d..f787a872 100644 --- a/implementation/tracing-propagation/src/main/java/io/smallrye/faulttolerance/tracing/TracingContextProvider.java +++ b/implementation/tracing-propagation/src/main/java/io/smallrye/faulttolerance/tracing/TracingContextProvider.java @@ -12,11 +12,7 @@ import io.opentracing.Tracer; import io.opentracing.util.GlobalTracer; -/** - * @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com - */ public class TracingContextProvider implements ThreadContextProvider { - private static final ThreadContextController DO_NOTHING = () -> { }; @@ -24,31 +20,36 @@ public class TracingContextProvider implements ThreadContextProvider { public ThreadContextSnapshot currentContext(Map props) { Tracer tracer = GlobalTracer.get(); ScopeManager scopeManager = tracer.scopeManager(); - Scope activeScope = scopeManager.active(); + Span span = scopeManager.activeSpan(); - if (activeScope != null) { - Span span = activeScope.span(); + if (span != null) { return () -> { - Scope propagated = scopeManager.activate(span, false); + Scope propagated = scopeManager.activate(span); return propagated::close; }; } + return () -> DO_NOTHING; } @Override public ThreadContextSnapshot clearedContext(Map props) { - return () -> { - Tracer tracer = GlobalTracer.get(); - ScopeManager scopeManager = tracer.scopeManager(); - Scope activeScope = scopeManager.active(); - if (activeScope != null) { - activeScope.close(); - } - return () -> { - // TODO: we should bring back the span here - }; - }; + // The OpenTracing API is apparently meant to be used in a way that + // never leaves scopes active. That is generally fine, but the API + // also doesn't provide a way to guard against misuse. That's because + // since OpenTracing 0.33, it is impossible to find "current" scope. + // So here, we just assume that the API is used correctly and there + // are no "dangling" scopes. + // + // Note that "active scope" is different from "active span". Span + // can be active for a long time, but once finished, it can't be + // reactivated. During the time a span is active, there are generally + // several slices of time when you actually work with it, and these + // slices are delimited by scopes. (In other words, creating a scope + // is akin to resuming a "paused" span, and closing a scope is akin + // to suspending a "running" span.) + + return () -> DO_NOTHING; } @Override diff --git a/pom.xml b/pom.xml index ea094089..dd10a6f4 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ 1.0.20 1.5.0 1.4.0 - 0.31.0 + 0.33.0 1.1.0 0.13.0 diff --git a/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/TracingContextPropagationTest.java b/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/TracingContextPropagationTest.java index 71e10a52..8b8ad487 100644 --- a/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/TracingContextPropagationTest.java +++ b/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/TracingContextPropagationTest.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; import io.opentracing.Scope; +import io.opentracing.Span; import io.opentracing.mock.MockSpan; import io.opentracing.util.GlobalTracerTestUtil; import io.smallrye.faulttolerance.util.FaultToleranceIntegrationTest; @@ -43,8 +44,11 @@ public static void reset() { @Test public void testCircuitBreakerOpens(Service service) { - try (Scope ignored = Service.mockTracer.buildSpan("parent").startActive(true)) { + Span span = Service.mockTracer.buildSpan("parent").start(); + try (Scope ignored = Service.mockTracer.scopeManager().activate(span)) { assertThat(service.foo()).isEqualTo("fallback"); + } finally { + span.finish(); } List mockSpans = Service.mockTracer.finishedSpans(); @@ -61,8 +65,11 @@ public void testCircuitBreakerOpens(Service service) { @Test public void testAsyncCircuitBreakerOpens(Service service) throws ExecutionException, InterruptedException { - try (Scope ignored = Service.mockTracer.buildSpan("parent").startActive(true)) { + Span span = Service.mockTracer.buildSpan("parent").start(); + try (Scope ignored = Service.mockTracer.scopeManager().activate(span)) { assertThat(service.asyncFoo().toCompletableFuture().get()).isEqualTo("asyncFallback"); + } finally { + span.finish(); } List mockSpans = Service.mockTracer.finishedSpans(); diff --git a/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/stress/TracingContextPropagationStressTest.java b/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/stress/TracingContextPropagationStressTest.java index adba5d2b..bb63a8a1 100644 --- a/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/stress/TracingContextPropagationStressTest.java +++ b/testsuite/integration/src/test/java/io/smallrye/faulttolerance/tracing/stress/TracingContextPropagationStressTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; import io.opentracing.Scope; +import io.opentracing.Span; import io.opentracing.mock.MockSpan; import io.opentracing.util.GlobalTracerTestUtil; import io.smallrye.faulttolerance.util.FaultToleranceIntegrationTest; @@ -47,8 +48,11 @@ public void test(Service service) throws ExecutionException, InterruptedExceptio } private void doTest(Service service) throws ExecutionException, InterruptedException { - try (Scope ignored = Service.tracer.buildSpan("parent").startActive(true)) { + Span span = Service.tracer.buildSpan("parent").start(); + try (Scope ignored = Service.tracer.scopeManager().activate(span)) { assertThat(service.hello().toCompletableFuture().get()).isEqualTo("fallback"); + } finally { + span.finish(); } await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { From 93ff5fc971671633270f7f06fc0d8e7172b5bd21 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Thu, 14 Jan 2021 18:16:07 +0100 Subject: [PATCH 2/2] improve commit messages for antora.yml updates --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b2621510..0108c704 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,13 +41,13 @@ jobs: git checkout -b release sed -i -e 's|^version: master|version: ${{steps.metadata.outputs.current-version}}|' doc/antora.yml sed -i -e 's|smallrye-fault-tolerance-version: .*|smallrye-fault-tolerance-version: '"'"'${{steps.metadata.outputs.current-version}}'"'"'|' doc/antora.yml - git commit -a -m 'Update antora.yml for release' + git commit -a -m 'Update antora.yml before release' mvn -B release:prepare -Prelease -DreleaseVersion=${{steps.metadata.outputs.current-version}} -DdevelopmentVersion=${{steps.metadata.outputs.next-version}} -s maven-settings.xml git checkout ${{github.base_ref}} git rebase release mvn -B release:perform -Prelease -s maven-settings.xml sed -i -e 's|^version: ${{steps.metadata.outputs.current-version}}|version: master|' doc/antora.yml - git commit -a -m 'Update antora.yml for release' + git commit -a -m 'Update antora.yml after release' git push git push --tags