use of io.grpc.ServerStreamTracer in project grpc-java by grpc.
the class CensusModulesTest method serverTracingSampledToLocalSpanStore.
@Test
public void serverTracingSampledToLocalSpanStore() {
ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
ServerStreamTracer serverStreamTracer = tracerFactory.newServerStreamTracer(sampledMethod.getFullMethodName(), new Metadata());
serverStreamTracer.filterContext(Context.ROOT);
serverStreamTracer.serverCallStarted(new CallInfo<>(sampledMethod, Attributes.EMPTY, null));
serverStreamTracer.streamClosed(Status.CANCELLED);
verify(spyServerSpan).end(EndSpanOptions.builder().setStatus(io.opencensus.trace.Status.CANCELLED).setSampleToLocalSpanStore(true).build());
}
use of io.grpc.ServerStreamTracer in project grpc-java by grpc.
the class CensusModulesTest method serverBasicTracingNoHeaders.
@Test
public void serverBasicTracingNoHeaders() {
ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
ServerStreamTracer serverStreamTracer = tracerFactory.newServerStreamTracer(method.getFullMethodName(), new Metadata());
verifyNoInteractions(mockTracingPropagationHandler);
verify(tracer).spanBuilderWithRemoteParent(eq("Recv.package1.service2.method3"), ArgumentMatchers.<SpanContext>isNull());
verify(spyServerSpanBuilder).setRecordEvents(eq(true));
Context filteredContext = serverStreamTracer.filterContext(Context.ROOT);
assertSame(spyServerSpan, ContextUtils.getValue(filteredContext));
serverStreamTracer.serverCallStarted(new CallInfo<>(method, Attributes.EMPTY, null));
verify(spyServerSpan, never()).end(any(EndSpanOptions.class));
serverStreamTracer.outboundMessage(0);
serverStreamTracer.outboundMessageSent(0, 882, -1);
serverStreamTracer.inboundMessage(0);
serverStreamTracer.outboundMessage(1);
serverStreamTracer.outboundMessageSent(1, -1, 27);
serverStreamTracer.inboundMessageRead(0, 255, 90);
serverStreamTracer.streamClosed(Status.CANCELLED);
InOrder inOrder = inOrder(spyServerSpan);
inOrder.verify(spyServerSpan, times(3)).addMessageEvent(messageEventCaptor.capture());
List<MessageEvent> events = messageEventCaptor.getAllValues();
assertEquals(MessageEvent.builder(MessageEvent.Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
assertEquals(MessageEvent.builder(MessageEvent.Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
assertEquals(MessageEvent.builder(MessageEvent.Type.RECEIVED, 0).setCompressedMessageSize(255).setUncompressedMessageSize(90).build(), events.get(2));
inOrder.verify(spyServerSpan).end(EndSpanOptions.builder().setStatus(io.opencensus.trace.Status.CANCELLED).setSampleToLocalSpanStore(false).build());
verifyNoMoreInteractions(spyServerSpan);
}
use of io.grpc.ServerStreamTracer in project grpc-java by grpc.
the class OrcaMetricReportingServerInterceptorTest method shareCallMetricRecorderInContext.
@Test
public void shareCallMetricRecorderInContext() throws IOException {
final CallMetricRecorder callMetricRecorder = InternalCallMetricRecorder.newCallMetricRecorder();
ServerStreamTracer.Factory callMetricRecorderSharingStreamTracerFactory = new ServerStreamTracer.Factory() {
@Override
public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata headers) {
return new ServerStreamTracer() {
@Override
public Context filterContext(Context context) {
return context.withValue(InternalCallMetricRecorder.CONTEXT_KEY, callMetricRecorder);
}
};
}
};
final AtomicReference<CallMetricRecorder> callMetricRecorderCapture = new AtomicReference<>();
SimpleServiceGrpc.SimpleServiceImplBase simpleServiceImpl = new SimpleServiceGrpc.SimpleServiceImplBase() {
@Override
public void unaryRpc(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
callMetricRecorderCapture.set(CallMetricRecorder.getCurrent());
SimpleResponse response = SimpleResponse.newBuilder().setResponseMessage("Simple response").build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
};
ServerInterceptor metricReportingServerInterceptor = new OrcaMetricReportingServerInterceptor();
String serverName = InProcessServerBuilder.generateName();
grpcCleanupRule.register(InProcessServerBuilder.forName(serverName).directExecutor().addStreamTracerFactory(callMetricRecorderSharingStreamTracerFactory).addService(ServerInterceptors.intercept(simpleServiceImpl, metricReportingServerInterceptor)).build().start());
ManagedChannel channel = grpcCleanupRule.register(InProcessChannelBuilder.forName(serverName).build());
ClientCalls.blockingUnaryCall(channel, SIMPLE_METHOD, CallOptions.DEFAULT, REQUEST);
assertThat(callMetricRecorderCapture.get()).isSameInstanceAs(callMetricRecorder);
}
use of io.grpc.ServerStreamTracer in project grpc-java by grpc.
the class StatsTraceContext method serverFilterContext.
/**
* See {@link ServerStreamTracer#filterContext}. For server-side only.
*
* <p>Called from {@link io.grpc.internal.ServerImpl}.
*/
public <ReqT, RespT> Context serverFilterContext(Context context) {
Context ctx = checkNotNull(context, "context");
for (StreamTracer tracer : tracers) {
ctx = ((ServerStreamTracer) tracer).filterContext(ctx);
checkNotNull(ctx, "%s returns null context", tracer);
}
return ctx;
}
use of io.grpc.ServerStreamTracer in project grpc-java by grpc.
the class CensusModulesTest method serverTracingNotSampledToLocalSpanStore_whenServerCallNotCreated.
@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());
}
Aggregations