/** * Create a callable object with grpc-specific functionality. Designed for use by generated code. * * @param grpcCallSettings the gRPC call settings */ public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createUnaryCallable( GrpcCallSettings<RequestT, ResponseT> grpcCallSettings, UnaryCallSettings<RequestT, ResponseT> callSettings, ClientContext clientContext) { UnaryCallable<RequestT, ResponseT> callable = createBaseUnaryCallable(grpcCallSettings, callSettings, clientContext); callable = new TracedUnaryCallable<>( callable, clientContext.getTracerFactory(), getSpanName(grpcCallSettings.getMethodDescriptor())); return callable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
/** * Create a callable object with grpc-specific functionality. Designed for use by generated code. * * @param grpcCallSettings the gRPC call settings */ public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createUnaryCallable( GrpcCallSettings<RequestT, ResponseT> grpcCallSettings, UnaryCallSettings<RequestT, ResponseT> callSettings, ClientContext clientContext) { UnaryCallable<RequestT, ResponseT> callable = createBaseUnaryCallable(grpcCallSettings, callSettings, clientContext); callable = new TracedUnaryCallable<>( callable, clientContext.getTracerFactory(), getSpanName(grpcCallSettings.getMethodDescriptor())); return callable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
/** * Create a bidirectional streaming callable object with grpc-specific functionality. Designed for * use by generated code. * * @param grpcCallSettings the gRPC call settings * @param streamingCallSettings {@link StreamingCallSettings} to configure the method-level * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @return {@link BidiStreamingCallable} callable object. */ @BetaApi("The surface for streaming is not stable yet and may change in the future.") public static <RequestT, ResponseT> BidiStreamingCallable<RequestT, ResponseT> createBidiStreamingCallable( GrpcCallSettings<RequestT, ResponseT> grpcCallSettings, StreamingCallSettings<RequestT, ResponseT> streamingCallSettings, ClientContext clientContext) { BidiStreamingCallable<RequestT, ResponseT> callable = new GrpcDirectBidiStreamingCallable<>(grpcCallSettings.getMethodDescriptor()); callable = new GrpcExceptionBidiStreamingCallable<>(callable, ImmutableSet.<StatusCode.Code>of()); callable = new TracedBidiCallable<>( callable, clientContext.getTracerFactory(), getSpanName(grpcCallSettings.getMethodDescriptor())); return callable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
@Test public void testGetSpanNameUnqualified() { @SuppressWarnings("unchecked") MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName("UnqualifiedService/ReadRows") .setRequestMarshaller(Mockito.mock(Marshaller.class)) .setResponseMarshaller(Mockito.mock(Marshaller.class)) .build(); SpanName actualSpanName = GrpcCallableFactory.getSpanName(descriptor); assertThat(actualSpanName).isEqualTo(SpanName.of("UnqualifiedService", "ReadRows")); }
@Test public void testGetSpanName() { @SuppressWarnings("unchecked") MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName("google.bigtable.v2.Bigtable/ReadRows") .setRequestMarshaller(Mockito.mock(Marshaller.class)) .setResponseMarshaller(Mockito.mock(Marshaller.class)) .build(); SpanName actualSpanName = GrpcCallableFactory.getSpanName(descriptor); assertThat(actualSpanName).isEqualTo(SpanName.of("Bigtable", "ReadRows")); }
@Test public void testGetSpanNameInvalid() { List<String> invalidNames = ImmutableList.of("BareMethod", "/MethodWithoutService"); for (String invalidName : invalidNames) { @SuppressWarnings("unchecked") MethodDescriptor descriptor = MethodDescriptor.newBuilder() .setType(MethodType.SERVER_STREAMING) .setFullMethodName(invalidName) .setRequestMarshaller(Mockito.mock(Marshaller.class)) .setResponseMarshaller(Mockito.mock(Marshaller.class)) .build(); IllegalArgumentException actualError = null; try { SpanName spanName = GrpcCallableFactory.getSpanName(descriptor); Truth.assertWithMessage("Invalid method descriptor should not have a valid span name") .fail("%s should not generate the spanName: %s", invalidName, spanName); } catch (IllegalArgumentException e) { actualError = e; } assertThat(actualError).isNotNull(); } } }
/** * Create a callable object that represents a batching API method. Designed for use by generated * code. * * @param grpcCallSettings the gRPC call settings * @param batchingCallSettings {@link BatchingCallSettings} to configure the batching related * settings with. * @param clientContext {@link ClientContext} to use to connect to the service. * @return {@link UnaryCallable} callable object. */ @BetaApi("The surface for batching is not stable yet and may change in the future.") public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createBatchingCallable( GrpcCallSettings<RequestT, ResponseT> grpcCallSettings, BatchingCallSettings<RequestT, ResponseT> batchingCallSettings, ClientContext clientContext) { UnaryCallable<RequestT, ResponseT> baseCallable = createBaseUnaryCallable(grpcCallSettings, batchingCallSettings, clientContext); // NOTE: Since batching happens asynchronously and the outermost callable simply buffers the // request. Tracing will only start on the inner callable that accepts the batch. UnaryCallable<RequestT, ResponseT> tracedCallable = new TracedBatchingCallable<>( baseCallable, clientContext.getTracerFactory(), getSpanName(grpcCallSettings.getMethodDescriptor()), batchingCallSettings.getBatchingDescriptor()); UnaryCallable<RequestT, ResponseT> batchingCallable = Callables.batching(tracedCallable, batchingCallSettings, clientContext); return batchingCallable.withDefaultCallContext(clientContext.getDefaultCallContext()); }
callable, clientContext.getTracerFactory(), getSpanName(grpcCallSettings.getMethodDescriptor()));