Wrap GRPC span start into scope
@@ -16,6 +16,7 @@ import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.propagation.Format;
+import io.opentracing.util.GlobalTracer;
public class TracingClientInterceptor implements ClientInterceptor {
@@ -36,10 +37,11 @@ public class TracingClientInterceptor implements ClientInterceptor {
.buildSpan("grpc.client")
.withTag(DDTags.RESOURCE_NAME, method.getFullMethodName())
.start();
+ try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
DECORATE.afterStart(span);
final ClientCall<ReqT, RespT> result;
- try (final Scope ignore = tracer.scopeManager().activate(span, false)) {
+ try {
// call other interceptors
result = next.newCall(method, callOptions);
} catch (final Throwable e) {
@@ -51,6 +53,7 @@ public class TracingClientInterceptor implements ClientInterceptor {
return new TracingClientCall<>(tracer, span, result);
}
+ }
static final class TracingClientCall<ReqT, RespT>
extends ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT> {
