Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to OpenTracing 0.33 #360

Merged
merged 2 commits into from Jan 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Expand Up @@ -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

Expand Down
Expand Up @@ -12,43 +12,44 @@
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 = () -> {
};

@Override
public ThreadContextSnapshot currentContext(Map<String, String> 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;
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at this again and I found this a bit weird. If the original thread had an active span, but not an active scope, the new thread will have the same active span, but it will also have an active scope.

I have read through opentracing/opentracing-java#267 and opentracing/opentracing-java#291 and it seems to me that OpenTracing just actively fights against our progamming model :-)

But I guess there's nothing better that we could do.


return () -> DO_NOTHING;
}

@Override
public ThreadContextSnapshot clearedContext(Map<String, String> 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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -45,7 +45,7 @@
<version.smallrye-context-propagation>1.0.20</version.smallrye-context-propagation>
<version.smallrye-common>1.5.0</version.smallrye-common>
<version.smallrye-reactive-utils>1.4.0</version.smallrye-reactive-utils>
<version.opentracing>0.31.0</version.opentracing>
<version.opentracing>0.33.0</version.opentracing>

<version.junit-pioneer>1.1.0</version.junit-pioneer>
<version.mutiny>0.13.0</version.mutiny>
Expand Down
Expand Up @@ -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;
Expand All @@ -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<MockSpan> mockSpans = Service.mockTracer.finishedSpans();
Expand All @@ -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<MockSpan> mockSpans = Service.mockTracer.finishedSpans();
Expand Down
Expand Up @@ -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;
Expand All @@ -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(() -> {
Expand Down