Java Code Examples for io.grpc.ServerStreamTracer#serverCallStarted()

The following examples show how to use io.grpc.ServerStreamTracer#serverCallStarted() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CensusModulesTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void serverTracingSampledToLocalSpanStore() {
  ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
  ServerStreamTracer serverStreamTracer =
      tracerFactory.newServerStreamTracer(sampledMethod.getFullMethodName(), new Metadata());

  serverStreamTracer.filterContext(Context.ROOT);

  serverStreamTracer.serverCallStarted(
      new ServerCallInfoImpl<String, String>(sampledMethod, Attributes.EMPTY, null));

  serverStreamTracer.streamClosed(Status.CANCELLED);

  verify(spyServerSpan).end(
      EndSpanOptions.builder()
          .setStatus(io.opencensus.trace.Status.CANCELLED)
          .setSampleToLocalSpanStore(true)
          .build());
}
 
Example 2
Source File: CensusModulesTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: CensusModulesTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Test
public void serverBasicTracingNoHeaders() {
  ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
  ServerStreamTracer serverStreamTracer =
      tracerFactory.newServerStreamTracer(method.getFullMethodName(), new Metadata());
  verifyZeroInteractions(mockTracingPropagationHandler);
  verify(tracer).spanBuilderWithRemoteParent(
      eq("Recv.package1.service2.method3"), isNull(SpanContext.class));
  verify(spyServerSpanBuilder).setRecordEvents(eq(true));

  Context filteredContext = serverStreamTracer.filterContext(Context.ROOT);
  assertSame(spyServerSpan, ContextUtils.CONTEXT_SPAN_KEY.get(filteredContext));

  serverStreamTracer.serverCallStarted(
      new ServerCallInfoImpl<String, String>(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(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
  assertEquals(
      MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
  assertEquals(
      MessageEvent.builder(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);
}
 
Example 4
Source File: CensusModulesTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void serverBasicTracingNoHeaders() {
  ServerStreamTracer.Factory tracerFactory = censusTracing.getServerTracerFactory();
  ServerStreamTracer serverStreamTracer =
      tracerFactory.newServerStreamTracer(method.getFullMethodName(), new Metadata());
  verifyZeroInteractions(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(Type.SENT, 0).setCompressedMessageSize(882).build(), events.get(0));
  assertEquals(
      MessageEvent.builder(Type.SENT, 1).setUncompressedMessageSize(27).build(), events.get(1));
  assertEquals(
      MessageEvent.builder(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);
}