@Test
  public void testSetServerSendInCaseOfThreadDuration() throws UnsupportedEncodingException {
    when(mockServerSpan.getSpan()).thenReturn(mockSpan);
    when(mockServerSpanState.getCurrentServerSpan()).thenReturn(mockServerSpan);
    when(mockServerSpanState.getServerSpanThreadDuration()).thenReturn(DURATION_MS);
    when(mockServerSpanState.getServerEndPoint()).thenReturn(mockEndPoint);
    serverTracer.setServerSend();
    verify(mockServerSpanState, times(3)).getCurrentServerSpan();
    verify(mockServerSpanState, times(2)).getServerEndPoint();

    final Annotation expectedServerSendAnnotation = new Annotation();
    expectedServerSendAnnotation.setHost(mockEndPoint);
    expectedServerSendAnnotation.setValue(zipkinCoreConstants.SERVER_SEND);
    expectedServerSendAnnotation.setTimestamp(CURRENT_TIME_MICROSECONDS);

    final BinaryAnnotation expectedThreadDurationAnnotation = new BinaryAnnotation();
    expectedThreadDurationAnnotation.setAnnotation_type(AnnotationType.STRING);
    expectedThreadDurationAnnotation.setHost(mockEndPoint);
    expectedThreadDurationAnnotation.setKey(BraveAnnotations.THREAD_DURATION);
    final ByteBuffer bb = ByteBuffer.wrap(String.valueOf(DURATION_MS).getBytes("UTF-8"));
    expectedThreadDurationAnnotation.setValue(bb);

    verify(mockSpan).addToAnnotations(expectedServerSendAnnotation);
    verify(mockSpan).addToBinary_annotations(expectedThreadDurationAnnotation);

    verify(mockServerSpanState).getServerSpanThreadDuration();
    verify(mockSpanCollector).collect(mockSpan);
    verify(mockServerSpanState).setCurrentServerSpan(null);
    verifyNoMoreInteractions(mockServerSpanState, mockSpanCollector, mockSpan);
  }
 public ZipkinSpanBuilder data(Map<String, String> data) {
   List<BinaryAnnotation> binaryAnnotations = Lists.newArrayList();
   for (Entry<String, String> entry : data.entrySet()) {
     BinaryAnnotation binaryAnnotation = new BinaryAnnotation();
     binaryAnnotation.setAnnotation_type(AnnotationType.BYTES);
     binaryAnnotation.setKey(entry.getKey());
     binaryAnnotation.setValue(entry.getValue().getBytes());
     binaryAnnotation.setHost(endPoint);
     binaryAnnotations.add(binaryAnnotation);
   }
   zipkinSpan.setBinary_annotations(binaryAnnotations);
   return this;
 }
예제 #3
0
  /** {@inheritDoc} */
  @Override
  public void addDefaultAnnotation(final String key, final String value) {
    Validate.notEmpty(key);
    Validate.notNull(value);

    try {
      final ByteBuffer bb = ByteBuffer.wrap(value.getBytes(UTF_8));

      final BinaryAnnotation binaryAnnotation = new BinaryAnnotation();
      binaryAnnotation.setKey(key);
      binaryAnnotation.setValue(bb);
      binaryAnnotation.setAnnotation_type(AnnotationType.STRING);
      defaultAnnotations.add(binaryAnnotation);

    } catch (final UnsupportedEncodingException e) {
      throw new IllegalStateException(e);
    }
  }