diff --git a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java index 21336e831b..39a5555dd3 100644 --- a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java +++ b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/BenchmarkServiceGrpc.java @@ -47,7 +47,7 @@ public final class BenchmarkServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.BenchmarkService", "UnaryCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Messages.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -79,7 +79,7 @@ public final class BenchmarkServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.BenchmarkService", "StreamingCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Messages.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -111,7 +111,7 @@ public final class BenchmarkServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.BenchmarkService", "StreamingFromClient")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Messages.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -143,7 +143,7 @@ public final class BenchmarkServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.BenchmarkService", "StreamingFromServer")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Messages.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -175,7 +175,7 @@ public final class BenchmarkServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.BenchmarkService", "StreamingBothWays")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Messages.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/ReportQpsScenarioServiceGrpc.java b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/ReportQpsScenarioServiceGrpc.java index e7ccfd4410..65fa3f3b36 100644 --- a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/ReportQpsScenarioServiceGrpc.java +++ b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/ReportQpsScenarioServiceGrpc.java @@ -47,7 +47,7 @@ public final class ReportQpsScenarioServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.ReportQpsScenarioService", "ReportScenario")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Control.ScenarioResult.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java index b36b8d5c74..6cbd02388a 100644 --- a/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java +++ b/benchmarks/src/generated/main/grpc/io/grpc/benchmarks/proto/WorkerServiceGrpc.java @@ -47,7 +47,7 @@ public final class WorkerServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.WorkerService", "RunServer")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Control.ServerArgs.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -79,7 +79,7 @@ public final class WorkerServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.WorkerService", "RunClient")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Control.ClientArgs.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -111,7 +111,7 @@ public final class WorkerServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.WorkerService", "CoreCount")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Control.CoreRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -143,7 +143,7 @@ public final class WorkerServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.WorkerService", "QuitWorker")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.benchmarks.proto.Control.Void.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/build.gradle b/build.gradle index 73a33647a4..ef6d1726c7 100644 --- a/build.gradle +++ b/build.gradle @@ -191,8 +191,8 @@ subprojects { google_auth_credentials: 'com.google.auth:google-auth-library-credentials:0.4.0', okhttp: 'com.squareup.okhttp:okhttp:2.5.0', okio: 'com.squareup.okio:okio:1.6.0', - opencensus_api: 'io.opencensus:opencensus-api:0.7.0', - opencensus_impl: 'io.opencensus:opencensus-impl:0.7.0', + opencensus_api: 'io.opencensus:opencensus-api:0.8.0', + opencensus_impl: 'io.opencensus:opencensus-impl:0.8.0', instrumentation_api: 'com.google.instrumentation:instrumentation-api:0.4.3', protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}", protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1", diff --git a/compiler/src/java_plugin/cpp/java_generator.cpp b/compiler/src/java_plugin/cpp/java_generator.cpp index 91aa78c80b..ad818b532e 100644 --- a/compiler/src/java_plugin/cpp/java_generator.cpp +++ b/compiler/src/java_plugin/cpp/java_generator.cpp @@ -363,7 +363,7 @@ static void PrintMethodFields( " .setType($MethodType$.$method_type$)\n" " .setFullMethodName(generateFullMethodName(\n" " \"$Package$$service_name$\", \"$method_name$\"))\n" - " .setRegisterForTracing(true)\n" + " .setSampledToLocalTracing(true)\n" " .setRequestMarshaller($NanoUtils$.<$input_type$>marshaller(\n" " new NanoFactory<$input_type$>(ARG_IN_$method_field_name$)))\n" " .setResponseMarshaller($NanoUtils$.<$output_type$>marshaller(\n" @@ -402,7 +402,7 @@ static void PrintMethodFields( " .setType($MethodType$.$method_type$)\n" " .setFullMethodName(generateFullMethodName(\n" " \"$Package$$service_name$\", \"$method_name$\"))\n" - " .setRegisterForTracing(true)\n" + " .setSampledToLocalTracing(true)\n" " .setRequestMarshaller($ProtoUtils$.marshaller(\n" " $input_type$.getDefaultInstance()))\n" " .setResponseMarshaller($ProtoUtils$.marshaller(\n" diff --git a/compiler/src/test/golden/TestService.java.txt b/compiler/src/test/golden/TestService.java.txt index 54f3955c7d..0555048858 100644 --- a/compiler/src/test/golden/TestService.java.txt +++ b/compiler/src/test/golden/TestService.java.txt @@ -50,7 +50,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "UnaryCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Test.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -82,7 +82,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingOutputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -114,7 +114,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingInputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Test.StreamingInputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -146,7 +146,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "FullBidiCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -178,7 +178,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "HalfBidiCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/compiler/src/testLite/golden/TestService.java.txt b/compiler/src/testLite/golden/TestService.java.txt index 412752f547..af8d0b66e6 100644 --- a/compiler/src/testLite/golden/TestService.java.txt +++ b/compiler/src/testLite/golden/TestService.java.txt @@ -50,7 +50,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "UnaryCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.integration.Test.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( @@ -81,7 +81,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingOutputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( @@ -112,7 +112,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingInputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.integration.Test.StreamingInputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( @@ -143,7 +143,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "FullBidiCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( @@ -174,7 +174,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "HalfBidiCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( io.grpc.testing.integration.Test.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller( diff --git a/compiler/src/testNano/golden/TestService.java.txt b/compiler/src/testNano/golden/TestService.java.txt index 8821167ed8..19ac8244e2 100644 --- a/compiler/src/testNano/golden/TestService.java.txt +++ b/compiler/src/testNano/golden/TestService.java.txt @@ -54,7 +54,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "UnaryCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( new NanoFactory(ARG_IN_METHOD_UNARY_CALL))) .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( @@ -87,7 +87,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingOutputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( new NanoFactory(ARG_IN_METHOD_STREAMING_OUTPUT_CALL))) .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( @@ -120,7 +120,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingInputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( new NanoFactory(ARG_IN_METHOD_STREAMING_INPUT_CALL))) .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( @@ -153,7 +153,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "FullBidiCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( new NanoFactory(ARG_IN_METHOD_FULL_BIDI_CALL))) .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( @@ -186,7 +186,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "HalfBidiCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( new NanoFactory(ARG_IN_METHOD_HALF_BIDI_CALL))) .setResponseMarshaller(io.grpc.protobuf.nano.NanoUtils.marshaller( diff --git a/core/src/main/java/io/grpc/InternalMethodDescriptor.java b/core/src/main/java/io/grpc/InternalMethodDescriptor.java index a8788f6ec1..303877e8aa 100644 --- a/core/src/main/java/io/grpc/InternalMethodDescriptor.java +++ b/core/src/main/java/io/grpc/InternalMethodDescriptor.java @@ -37,11 +37,4 @@ public final class InternalMethodDescriptor { public void setRawMethodName(MethodDescriptor md, Object o) { md.setRawMethodName(transport.ordinal(), o); } - - public interface RegisterForTracingCallback extends - MethodDescriptor.Registrations.RegisterForTracingCallback {} - - public static void setRegisterCallback(RegisterForTracingCallback registerCallback) { - MethodDescriptor.Registrations.setRegisterForTracingCallback(registerCallback); - } } diff --git a/core/src/main/java/io/grpc/MethodDescriptor.java b/core/src/main/java/io/grpc/MethodDescriptor.java index 45f4e58945..f908ddeec9 100644 --- a/core/src/main/java/io/grpc/MethodDescriptor.java +++ b/core/src/main/java/io/grpc/MethodDescriptor.java @@ -17,15 +17,9 @@ package io.grpc; import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; import com.google.common.base.Preconditions; import java.io.InputStream; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; import java.util.concurrent.atomic.AtomicReferenceArray; import javax.annotation.CheckReturnValue; import javax.annotation.Nullable; @@ -51,10 +45,7 @@ public final class MethodDescriptor { private final @Nullable Object schemaDescriptor; private final boolean idempotent; private final boolean safe; - // This field is not exposed, since the result would be misleading. Setting this value to true, - // ensures that the method is traced, but false means that it might still be traced, due to - // another descriptor tracing the same name. - private final boolean registerForTracing; + private final boolean sampledToLocalTracing; // Must be set to InternalKnownTransport.values().length // Not referenced to break the dependency. @@ -231,7 +222,7 @@ public final class MethodDescriptor { Object schemaDescriptor, boolean idempotent, boolean safe, - boolean registerForTracing) { + boolean sampledToLocalTracing) { this.type = Preconditions.checkNotNull(type, "type"); this.fullMethodName = Preconditions.checkNotNull(fullMethodName, "fullMethodName"); @@ -240,12 +231,9 @@ public final class MethodDescriptor { this.schemaDescriptor = schemaDescriptor; this.idempotent = idempotent; this.safe = safe; - this.registerForTracing = registerForTracing; + this.sampledToLocalTracing = sampledToLocalTracing; Preconditions.checkArgument(!safe || type == MethodType.UNARY, "Only unary methods can be specified safe"); - if (registerForTracing) { - Registrations.registerForTracing(this); - } } /** @@ -366,6 +354,13 @@ public final class MethodDescriptor { return safe; } + /** + * Returns whether RPCs for this method may be sampled into the local tracing store. + */ + public boolean isSampledToLocalTracing() { + return sampledToLocalTracing; + } + /** * Generate the fully qualified method name. * @@ -443,7 +438,7 @@ public final class MethodDescriptor { .setFullMethodName(fullMethodName) .setIdempotent(idempotent) .setSafe(safe) - .setRegisterForTracing(registerForTracing); + .setSampledToLocalTracing(sampledToLocalTracing); } /** @@ -460,7 +455,7 @@ public final class MethodDescriptor { private boolean idempotent; private boolean safe; private Object schemaDescriptor; - private boolean registerForTracing; + private boolean sampledToLocalTracing; private Builder() {} @@ -548,13 +543,13 @@ public final class MethodDescriptor { } /** - * Sets whether the new MethodDescriptor should be registered into the tracing system, so that - * RPCs on this method may be collected and stored. + * Sets whether RPCs for this method may be sampled into the local tracing store. If true, + * sampled traces of this method may be kept in memory by tracing libraries. * - * @since 1.7.0 + * @since 1.8.0 */ - public Builder setRegisterForTracing(boolean value) { - this.registerForTracing = value; + public Builder setSampledToLocalTracing(boolean value) { + this.sampledToLocalTracing = value; return this; } @@ -573,72 +568,7 @@ public final class MethodDescriptor { schemaDescriptor, idempotent, safe, - registerForTracing); - } - } - - static final class Registrations { - - private static final ReferenceQueue> droppedMethodDescriptors = - new ReferenceQueue>(); - private static final Collection>> pendingRegistrations = - new LinkedList>>(); - - private static volatile RegisterForTracingCallback registerCallback; - - interface RegisterForTracingCallback { - void onRegister(MethodDescriptor md); - } - - /** - * Sets a callback for method descriptor builds. Called for descriptors with - * {@link MethodDescriptor#registerForTracing} set. This should only be called by - * {@link io.grpc.internal.CensusTracingModule} since it will only work for one invocation. - * - * @param registerCallback the callback to handle descriptor registration. - */ - static synchronized void setRegisterForTracingCallback( - RegisterForTracingCallback registerCallback) { - checkState(Registrations.registerCallback == null, "callback already present"); - Registrations.registerCallback = checkNotNull(registerCallback, "registerCallback"); - for (WeakReference> mdRef : pendingRegistrations) { - MethodDescriptor md = mdRef.get(); - if (md != null) { - mdRef.clear(); - registerCallback.onRegister(md); - } - } - drainDroppedMethodDescriptors(); - } - - private static synchronized void drainDroppedMethodDescriptors() { - boolean found = false; - while (droppedMethodDescriptors.poll() != null) { - found = true; - } - if (found) { - Iterator>> it = pendingRegistrations.iterator(); - while (it.hasNext()) { - if (it.next().get() == null) { - it.remove(); - } - } - } - } - - private static void registerForTracing(MethodDescriptor md) { - RegisterForTracingCallback reg; - if ((reg = registerCallback) == null) { - synchronized (MethodDescriptor.class) { - if ((reg = registerCallback) == null) { - pendingRegistrations.add( - new WeakReference>(md, droppedMethodDescriptors)); - drainDroppedMethodDescriptors(); - return; - } - } - } - reg.onRegister(md); + sampledToLocalTracing); } } } diff --git a/core/src/main/java/io/grpc/ServerStreamTracer.java b/core/src/main/java/io/grpc/ServerStreamTracer.java index ab4eebaa25..7533d7716f 100644 --- a/core/src/main/java/io/grpc/ServerStreamTracer.java +++ b/core/src/main/java/io/grpc/ServerStreamTracer.java @@ -33,8 +33,9 @@ public abstract class ServerStreamTracer extends StreamTracer { } /** - * Called when {@link ServerCall} is created. This is for the tracer to access information - * about the {@code ServerCall}. + * Called when {@link ServerCall} is created. This is for the tracer to access information about + * the {@code ServerCall}. Called after {@link #filterContext} and before the application call + * handler. */ public void serverCallStarted(ServerCall call) { } diff --git a/core/src/main/java/io/grpc/internal/CensusTracingModule.java b/core/src/main/java/io/grpc/internal/CensusTracingModule.java index ce0f7dfe0f..626abb4aec 100644 --- a/core/src/main/java/io/grpc/internal/CensusTracingModule.java +++ b/core/src/main/java/io/grpc/internal/CensusTracingModule.java @@ -28,10 +28,9 @@ import io.grpc.ClientStreamTracer; import io.grpc.Context; import io.grpc.ForwardingClientCall.SimpleForwardingClientCall; import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener; -import io.grpc.InternalMethodDescriptor; -import io.grpc.InternalMethodDescriptor.RegisterForTracingCallback; import io.grpc.Metadata; import io.grpc.MethodDescriptor; +import io.grpc.ServerCall; import io.grpc.ServerStreamTracer; import io.grpc.StreamTracer; import io.opencensus.trace.EndSpanOptions; @@ -40,11 +39,7 @@ import io.opencensus.trace.Span; import io.opencensus.trace.SpanContext; import io.opencensus.trace.Status; import io.opencensus.trace.Tracer; -import io.opencensus.trace.Tracing; -import io.opencensus.trace.export.SampledSpanStore; import io.opencensus.trace.propagation.BinaryFormat; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.logging.Level; import java.util.logging.Logger; @@ -74,24 +69,6 @@ final class CensusTracingModule { private final TracingClientInterceptor clientInterceptor = new TracingClientInterceptor(); private final ServerTracerFactory serverTracerFactory = new ServerTracerFactory(); - private static final boolean isRegistered = registerCensusTracer(); - - private static boolean registerCensusTracer() { - InternalMethodDescriptor.setRegisterCallback(new RegisterForTracingCallback() { - @Override - public void onRegister(MethodDescriptor md) { - SampledSpanStore sampledStore = Tracing.getExportComponent().getSampledSpanStore(); - if (sampledStore != null) { - List spanNames = new ArrayList(2); - spanNames.add(generateTraceSpanName(false, md.getFullMethodName())); - spanNames.add(generateTraceSpanName(true, md.getFullMethodName())); - sampledStore.registerSpanNamesForCollection(spanNames); - } - } - }); - return true; - } - CensusTracingModule( Tracer censusTracer, final BinaryFormat censusPropagationBinaryFormat) { this.censusTracer = checkNotNull(censusTracer, "censusTracer"); @@ -119,8 +96,8 @@ final class CensusTracingModule { * Creates a {@link ClientCallTracer} for a new call. */ @VisibleForTesting - ClientCallTracer newClientCallTracer(@Nullable Span parentSpan, String fullMethodName) { - return new ClientCallTracer(parentSpan, fullMethodName); + ClientCallTracer newClientCallTracer(@Nullable Span parentSpan, MethodDescriptor method) { + return new ClientCallTracer(parentSpan, method); } /** @@ -201,8 +178,12 @@ final class CensusTracingModule { return status; } - private static EndSpanOptions createEndSpanOptions(io.grpc.Status status) { - return EndSpanOptions.builder().setStatus(convertStatus(status)).build(); + private static EndSpanOptions createEndSpanOptions( + io.grpc.Status status, boolean sampledToLocalTracing) { + return EndSpanOptions.builder() + .setStatus(convertStatus(status)) + .setSampleToLocalSpanStore(sampledToLocalTracing) + .build(); } private static void recordNetworkEvent( @@ -222,14 +203,16 @@ final class CensusTracingModule { final class ClientCallTracer extends ClientStreamTracer.Factory { volatile int callEnded; + private final boolean isSampledToLocalTracing; private final Span span; - ClientCallTracer(@Nullable Span parentSpan, String fullMethodName) { - checkNotNull(fullMethodName, "fullMethodName"); + ClientCallTracer(@Nullable Span parentSpan, MethodDescriptor method) { + checkNotNull(method, "method"); + this.isSampledToLocalTracing = method.isSampledToLocalTracing(); this.span = censusTracer .spanBuilderWithExplicitParent( - generateTraceSpanName(false, fullMethodName), + generateTraceSpanName(false, method.getFullMethodName()), parentSpan) .setRecordEvents(true) .startSpan(); @@ -252,7 +235,7 @@ final class CensusTracingModule { if (callEndedUpdater.getAndSet(this, 1) != 0) { return; } - span.end(createEndSpanOptions(status)); + span.end(createEndSpanOptions(status, isSampledToLocalTracing)); } } @@ -281,6 +264,7 @@ final class CensusTracingModule { private final class ServerTracer extends ServerStreamTracer { private final Span span; + volatile boolean isSampledToLocalTracing; volatile int streamClosed; ServerTracer(String fullMethodName, @Nullable SpanContext remoteSpan) { @@ -294,6 +278,11 @@ final class CensusTracingModule { .startSpan(); } + @Override + public void serverCallStarted(ServerCall call) { + isSampledToLocalTracing = call.getMethodDescriptor().isSampledToLocalTracing(); + } + /** * Record a finished stream and mark the current time as the end time. * @@ -305,7 +294,7 @@ final class CensusTracingModule { if (streamClosedUpdater.getAndSet(this, 1) != 0) { return; } - span.end(createEndSpanOptions(status)); + span.end(createEndSpanOptions(status, isSampledToLocalTracing)); } @Override @@ -353,8 +342,7 @@ final class CensusTracingModule { // Safe usage of the unsafe trace API because CONTEXT_SPAN_KEY.get() returns the same value // as Tracer.getCurrentSpan() except when no value available when the return value is null // for the direct access and BlankSpan when Tracer API is used. - final ClientCallTracer tracerFactory = - newClientCallTracer(CONTEXT_SPAN_KEY.get(), method.getFullMethodName()); + final ClientCallTracer tracerFactory = newClientCallTracer(CONTEXT_SPAN_KEY.get(), method); ClientCall call = next.newCall(method, callOptions.withStreamTracerFactory(tracerFactory)); return new SimpleForwardingClientCall(call) { diff --git a/core/src/test/java/io/grpc/MethodDescriptorTest.java b/core/src/test/java/io/grpc/MethodDescriptorTest.java index 9647214e4f..e3dffcb374 100644 --- a/core/src/test/java/io/grpc/MethodDescriptorTest.java +++ b/core/src/test/java/io/grpc/MethodDescriptorTest.java @@ -94,4 +94,36 @@ public class MethodDescriptorTest { // Never reached assert discard == null; } + + @Test + public void sampledToLocalTracing() { + MethodDescriptor md1 = MethodDescriptor.newBuilder() + .setType(MethodType.SERVER_STREAMING) + .setFullMethodName("/package.service/method") + .setRequestMarshaller(new StringMarshaller()) + .setResponseMarshaller(new StringMarshaller()) + .setSampledToLocalTracing(true) + .build(); + assertTrue(md1.isSampledToLocalTracing()); + + MethodDescriptor md2 = md1.toBuilder() + .setFullMethodName("/package.service/method2") + .build(); + assertTrue(md2.isSampledToLocalTracing()); + + // Same method name as md1, but not setting sampledToLocalTracing + MethodDescriptor md3 = MethodDescriptor.newBuilder() + .setType(MethodType.SERVER_STREAMING) + .setFullMethodName("/package.service/method") + .setRequestMarshaller(new StringMarshaller()) + .setResponseMarshaller(new StringMarshaller()) + .build(); + assertFalse(md3.isSampledToLocalTracing()); + + MethodDescriptor md4 = md3.toBuilder() + .setFullMethodName("/package.service/method2") + .setSampledToLocalTracing(true) + .build(); + assertTrue(md4.isSampledToLocalTracing()); + } } diff --git a/core/src/test/java/io/grpc/internal/CensusModulesTest.java b/core/src/test/java/io/grpc/internal/CensusModulesTest.java index c0fad718ca..8828db1599 100644 --- a/core/src/test/java/io/grpc/internal/CensusModulesTest.java +++ b/core/src/test/java/io/grpc/internal/CensusModulesTest.java @@ -133,6 +133,9 @@ public class CensusModulesTest { .setResponseMarshaller(MARSHALLER) .setFullMethodName("package1.service2/method3") .build(); + private final MethodDescriptor sampledMethod = + method.toBuilder().setSampledToLocalTracing(true).build(); + private final FakeClock fakeClock = new FakeClock(); private final FakeStatsContextFactory statsCtxFactory = new FakeStatsContextFactory(); private final Random random = new Random(1234); @@ -305,6 +308,7 @@ public class CensusModulesTest { .setStatus( io.opencensus.trace.Status.PERMISSION_DENIED .withDescription("No you don't")) + .setSampleToLocalSpanStore(false) .build()); verify(spyClientSpan, never()).end(); } @@ -362,7 +366,7 @@ public class CensusModulesTest { @Test public void clientBasicTracingDefaultSpan() { CensusTracingModule.ClientCallTracer callTracer = - censusTracing.newClientCallTracer(null, method.getFullMethodName()); + censusTracing.newClientCallTracer(null, method); Metadata headers = new Metadata(); ClientStreamTracer clientStreamTracer = callTracer.newClientStreamTracer(CallOptions.DEFAULT, headers); @@ -394,11 +398,28 @@ public class CensusModulesTest { .build(), events.get(2)); inOrder.verify(spyClientSpan).end( - EndSpanOptions.builder().setStatus(io.opencensus.trace.Status.OK).build()); + EndSpanOptions.builder() + .setStatus(io.opencensus.trace.Status.OK) + .setSampleToLocalSpanStore(false) + .build()); verifyNoMoreInteractions(spyClientSpan); verifyNoMoreInteractions(tracer); } + @Test + public void clientTracingSampledToLocalSpanStore() { + CensusTracingModule.ClientCallTracer callTracer = + censusTracing.newClientCallTracer(null, sampledMethod); + Metadata headers = new Metadata(); + callTracer.callEnded(Status.OK); + + verify(spyClientSpan).end( + EndSpanOptions.builder() + .setStatus(io.opencensus.trace.Status.OK) + .setSampleToLocalSpanStore(true) + .build()); + } + @Test public void clientStreamNeverCreatedStillRecordStats() { CensusStatsModule.ClientCallTracer callTracer = @@ -431,7 +452,7 @@ public class CensusModulesTest { @Test public void clientStreamNeverCreatedStillRecordTracing() { CensusTracingModule.ClientCallTracer callTracer = - censusTracing.newClientCallTracer(fakeClientParentSpan, method.getFullMethodName()); + censusTracing.newClientCallTracer(fakeClientParentSpan, method); verify(tracer).spanBuilderWithExplicitParent( eq("Sent.package1.service2.method3"), same(fakeClientParentSpan)); verify(spyClientSpanBuilder).setRecordEvents(eq(true)); @@ -442,6 +463,7 @@ public class CensusModulesTest { .setStatus( io.opencensus.trace.Status.DEADLINE_EXCEEDED .withDescription("3 seconds")) + .setSampleToLocalSpanStore(false) .build()); verifyNoMoreInteractions(spyClientSpan); } @@ -567,7 +589,7 @@ public class CensusModulesTest { @Test public void traceHeadersPropagateSpanContext() throws Exception { CensusTracingModule.ClientCallTracer callTracer = - censusTracing.newClientCallTracer(fakeClientParentSpan, method.getFullMethodName()); + censusTracing.newClientCallTracer(fakeClientParentSpan, method); Metadata headers = new Metadata(); callTracer.newClientStreamTracer(CallOptions.DEFAULT, headers); @@ -684,6 +706,8 @@ public class CensusModulesTest { Context filteredContext = serverStreamTracer.filterContext(Context.ROOT); assertSame(spyServerSpan, ContextUtils.CONTEXT_SPAN_KEY.get(filteredContext)); + serverStreamTracer.serverCallStarted(new FakeServerCall(method)); + verify(spyServerSpan, never()).end(any(EndSpanOptions.class)); serverStreamTracer.outboundMessage(0); @@ -710,10 +734,44 @@ public class CensusModulesTest { events.get(2)); inOrder.verify(spyServerSpan).end( EndSpanOptions.builder() - .setStatus(io.opencensus.trace.Status.CANCELLED).build()); + .setStatus(io.opencensus.trace.Status.CANCELLED) + .setSampleToLocalSpanStore(false) + .build()); verifyNoMoreInteractions(spyServerSpan); } + @Test + public void serverTracingSampledToLocalSpanStore() { + ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory(); + ServerStreamTracer serverStreamTracer = + tracerFactory.newServerStreamTracer(sampledMethod.getFullMethodName(), new Metadata()); + + serverStreamTracer.filterContext(Context.ROOT); + serverStreamTracer.serverCallStarted(new FakeServerCall(sampledMethod)); + serverStreamTracer.streamClosed(Status.CANCELLED); + + verify(spyServerSpan).end( + EndSpanOptions.builder() + .setStatus(io.opencensus.trace.Status.CANCELLED) + .setSampleToLocalSpanStore(true) + .build()); + } + + @Test + public void serverTracingNotSampledToLocalSpanStore_whenServerCallNotCreated() { + ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory(); + ServerStreamTracer serverStreamTracer = + tracerFactory.newServerStreamTracer(sampledMethod.getFullMethodName(), new Metadata()); + + serverStreamTracer.streamClosed(Status.CANCELLED); + + verify(spyServerSpan).end( + EndSpanOptions.builder() + .setStatus(io.opencensus.trace.Status.CANCELLED) + .setSampleToLocalSpanStore(false) + .build()); + } + @Test public void convertToTracingStatus() { // Without description @@ -767,4 +825,42 @@ public class CensusModulesTest { assertNull(record.getMetric(RpcConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES)); assertNull(record.getMetric(RpcConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES)); } + + private static class FakeServerCall extends ServerCall { + final MethodDescriptor method; + + FakeServerCall(MethodDescriptor method) { + this.method = method; + } + + @Override + public void request(int numMessages) { + throw new AssertionError("Should not be called"); + } + + @Override + public void sendHeaders(Metadata headers) { + throw new AssertionError("Should not be called"); + } + + @Override + public void sendMessage(RespT message) { + throw new AssertionError("Should not be called"); + } + + @Override + public void close(Status status, Metadata trailers) { + throw new AssertionError("Should not be called"); + } + + @Override + public boolean isCancelled() { + throw new AssertionError("Should not be called"); + } + + @Override + public MethodDescriptor getMethodDescriptor() { + return method; + } + } } diff --git a/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java b/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java index a6528e8dc6..b6d4c70783 100644 --- a/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java +++ b/grpclb/src/generated/main/grpc/io/grpc/grpclb/LoadBalancerGrpc.java @@ -47,7 +47,7 @@ public final class LoadBalancerGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.lb.v1.LoadBalancer", "BalanceLoad")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.grpclb.LoadBalanceRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java index 89ea037c53..c9e8ef195d 100644 --- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java +++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/MetricsServiceGrpc.java @@ -47,7 +47,7 @@ public final class MetricsServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.MetricsService", "GetAllGauges")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Metrics.EmptyMessage.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -79,7 +79,7 @@ public final class MetricsServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.MetricsService", "GetGauge")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Metrics.GaugeRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java index d98bfb1046..1d1157631a 100644 --- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java +++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/ReconnectServiceGrpc.java @@ -50,7 +50,7 @@ public final class ReconnectServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.ReconnectService", "Start")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.EmptyProtos.Empty.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -82,7 +82,7 @@ public final class ReconnectServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.ReconnectService", "Stop")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.EmptyProtos.Empty.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java index 7247a9221a..5578f19041 100644 --- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java +++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/TestServiceGrpc.java @@ -51,7 +51,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "EmptyCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.EmptyProtos.Empty.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -83,7 +83,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "UnaryCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Messages.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -115,7 +115,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "CacheableUnaryCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Messages.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -147,7 +147,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingOutputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Messages.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -179,7 +179,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "StreamingInputCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Messages.StreamingInputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -211,7 +211,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "FullDuplexCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Messages.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -243,7 +243,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "HalfDuplexCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.integration.Messages.StreamingOutputCallRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -275,7 +275,7 @@ public final class TestServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.TestService", "UnimplementedCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.EmptyProtos.Empty.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java index fd0db881d6..8bf42f1a18 100644 --- a/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java +++ b/interop-testing/src/generated/main/grpc/io/grpc/testing/integration/UnimplementedServiceGrpc.java @@ -51,7 +51,7 @@ public final class UnimplementedServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.UnimplementedService", "UnimplementedCall")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.EmptyProtos.Empty.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java b/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java index 82686726ce..e3f4f49a88 100644 --- a/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java +++ b/services/src/generated/main/grpc/io/grpc/health/v1/HealthGrpc.java @@ -47,7 +47,7 @@ public final class HealthGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.health.v1.Health", "Check")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.health.v1.HealthCheckRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/services/src/generated/main/grpc/io/grpc/instrumentation/v1alpha/MonitoringGrpc.java b/services/src/generated/main/grpc/io/grpc/instrumentation/v1alpha/MonitoringGrpc.java index 3782f32ec3..6da75b3e1c 100644 --- a/services/src/generated/main/grpc/io/grpc/instrumentation/v1alpha/MonitoringGrpc.java +++ b/services/src/generated/main/grpc/io/grpc/instrumentation/v1alpha/MonitoringGrpc.java @@ -47,7 +47,7 @@ public final class MonitoringGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.instrumentation.v1alpha.Monitoring", "GetCanonicalRpcStats")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( com.google.protobuf.Empty.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -79,7 +79,7 @@ public final class MonitoringGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.instrumentation.v1alpha.Monitoring", "GetStats")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.instrumentation.v1alpha.StatsRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -111,7 +111,7 @@ public final class MonitoringGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.instrumentation.v1alpha.Monitoring", "WatchStats")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.instrumentation.v1alpha.StatsRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -143,7 +143,7 @@ public final class MonitoringGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.instrumentation.v1alpha.Monitoring", "GetRequestTraces")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.instrumentation.v1alpha.TraceRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -175,7 +175,7 @@ public final class MonitoringGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.instrumentation.v1alpha.Monitoring", "GetCustomMonitoringData")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.instrumentation.v1alpha.MonitoringDataGroup.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/services/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java b/services/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java index a5cacdc9b9..fd03585c59 100644 --- a/services/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java +++ b/services/src/generated/main/grpc/io/grpc/reflection/v1alpha/ServerReflectionGrpc.java @@ -47,7 +47,7 @@ public final class ServerReflectionGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.reflection.v1alpha.ServerReflection", "ServerReflectionInfo")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.reflection.v1alpha.ServerReflectionRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/services/src/generated/test/grpc/io/grpc/reflection/testing/AnotherDynamicServiceGrpc.java b/services/src/generated/test/grpc/io/grpc/reflection/testing/AnotherDynamicServiceGrpc.java index a94747f75a..efbbd249ea 100644 --- a/services/src/generated/test/grpc/io/grpc/reflection/testing/AnotherDynamicServiceGrpc.java +++ b/services/src/generated/test/grpc/io/grpc/reflection/testing/AnotherDynamicServiceGrpc.java @@ -50,7 +50,7 @@ public final class AnotherDynamicServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.reflection.testing.AnotherDynamicService", "Method")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.reflection.testing.DynamicRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/services/src/generated/test/grpc/io/grpc/reflection/testing/DynamicServiceGrpc.java b/services/src/generated/test/grpc/io/grpc/reflection/testing/DynamicServiceGrpc.java index 6e23f881f0..d63ac4af25 100644 --- a/services/src/generated/test/grpc/io/grpc/reflection/testing/DynamicServiceGrpc.java +++ b/services/src/generated/test/grpc/io/grpc/reflection/testing/DynamicServiceGrpc.java @@ -50,7 +50,7 @@ public final class DynamicServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.reflection.testing.DynamicService", "Method")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.reflection.testing.DynamicRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/services/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java b/services/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java index b824948593..3650aa6972 100644 --- a/services/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java +++ b/services/src/generated/test/grpc/io/grpc/reflection/testing/ReflectableServiceGrpc.java @@ -47,7 +47,7 @@ public final class ReflectableServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.reflection.testing.ReflectableService", "Method")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.reflection.testing.Request.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/testing-proto/build.gradle b/testing-proto/build.gradle index bda787f93e..84f651af4c 100644 --- a/testing-proto/build.gradle +++ b/testing-proto/build.gradle @@ -13,9 +13,7 @@ buildscript { dependencies { compile project(':grpc-protobuf'), project(':grpc-stub') - testCompile libraries.opencensus_api, - libraries.truth - testRuntime libraries.opencensus_impl + testCompile libraries.truth } configureProtoCompilation() diff --git a/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java b/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java index 64a600e268..1bd2fe89ca 100644 --- a/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java +++ b/testing-proto/src/generated/main/grpc/io/grpc/testing/protobuf/SimpleServiceGrpc.java @@ -50,7 +50,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "UnaryRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -82,7 +82,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "ClientStreamingRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -114,7 +114,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "ServerStreamingRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( @@ -146,7 +146,7 @@ public final class SimpleServiceGrpc { .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) .setFullMethodName(generateFullMethodName( "grpc.testing.SimpleService", "BidiStreamingRpc")) - .setRegisterForTracing(true) + .setSampledToLocalTracing(true) .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( io.grpc.testing.protobuf.SimpleRequest.getDefaultInstance())) .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( diff --git a/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java b/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java index a6381cccb0..3dce5d9751 100644 --- a/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java +++ b/testing-proto/src/test/java/io/grpc/testing/protobuf/SimpleServiceTest.java @@ -16,19 +16,14 @@ package io.grpc.testing.protobuf; -import static com.google.common.truth.Truth.assertThat; import static io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING; import static io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING; import static io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING; import static io.grpc.MethodDescriptor.MethodType.UNARY; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import io.grpc.MethodDescriptor; -import io.opencensus.trace.Tracing; -import io.opencensus.trace.export.SampledSpanStore; -import java.util.ArrayList; -import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -59,33 +54,7 @@ public class SimpleServiceTest { } @Test - public void registerSampledMethodsForTracing() throws Exception { - // Make sure SimpleServiceGrpc and CensusTracingModule classes are loaded. - assertNotNull(Class.forName(SimpleServiceGrpc.class.getName())); - assertNotNull(Class.forName("io.grpc.internal.CensusTracingModule")); - - String[] methodNames = new String[] { - "grpc.testing.SimpleService/UnaryRpc", - "grpc.testing.SimpleService/ClientStreamingRpc", - "grpc.testing.SimpleService/ServerStreamingRpc", - "grpc.testing.SimpleService/BidiStreamingRpc"}; - - ArrayList expectedSpans = new ArrayList(); - for (String methodName : methodNames) { - expectedSpans.add(generateTraceSpanName(false, methodName)); - expectedSpans.add(generateTraceSpanName(true, methodName)); - } - - SampledSpanStore sampledStore = Tracing.getExportComponent().getSampledSpanStore(); - Set registeredSpans = sampledStore.getRegisteredSpanNamesForCollection(); - assertThat(registeredSpans).containsAllIn(expectedSpans); - } - - /** - * Copy of {@link io.grpc.internal.CensusTracingModule#generateTraceSpanName} to break dependency. - */ - private static String generateTraceSpanName(boolean isServer, String fullMethodName) { - String prefix = isServer ? "Recv" : "Sent"; - return prefix + "." + fullMethodName.replace('/', '.'); + public void generatedMethodsAreSampledToLocalTracing() throws Exception { + assertTrue(SimpleServiceGrpc.getUnaryRpcMethod().isSampledToLocalTracing()); } }