/** * Adds a {@link TimestampedAnnotation} to this Span's {@link #getTimestampedAnnotations()} list, with the current * time in epoch microseconds as the timestamp and the given value. * * <p>NOTE: Since the span keeps track of its duration in nanoseconds, this method results in a * {@link TimestampedAnnotation} with a {@link TimestampedAnnotation#getTimestampEpochMicros()} that is more * accurate than if you created the {@link TimestampedAnnotation} directly (i.e. this method uses {@link * TimestampedAnnotation#forEpochMicrosWithNanoOffset(long, long, String)}). This method should therefore be * used anytime you want to add an annotation to a Span with a timestamp of "right now". * * @param value The desired {@link TimestampedAnnotation#getValue()} for the new annotation. */ public void addTimestampedAnnotationForCurrentTime(String value) { addTimestampedAnnotation( TimestampedAnnotation.forEpochMicrosWithNanoOffset( spanStartTimeEpochMicros, System.nanoTime() - spanStartTimeNanos, value ) ); }
subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicrosWithNanoOffset( subspan.getSpanStartTimeEpochMicros(), -connectionSetupTimeNanos, subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicros( subspan.getSpanStartTimeEpochMicros(), proxySpanTaggingStrategy.connFinishAnnotationName()
subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicrosWithNanoOffset( subspan.getSpanStartTimeEpochMicros(), -connectionSetupTimeNanos, subspan.addTimestampedAnnotation(TimestampedAnnotation.forEpochMicros( subspan.getSpanStartTimeEpochMicros(), proxySpanTaggingStrategy.connFinishAnnotationName()
@Test public void addTimestampedAnnotation_works_as_expected() { // given Span span = Span.newBuilder("foo", SpanPurpose.CLIENT).build(); TimestampedAnnotation annotationMock = mock(TimestampedAnnotation.class); // when span.addTimestampedAnnotation(annotationMock); // then assertThat(span.getTimestampedAnnotations()) .hasSize(1) .containsExactly(annotationMock); }
@Test public void equals_returns_false_and_hashCode_different_if_annotations_are_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); fullSpan1.addTimestampedAnnotation(TimestampedAnnotation.forCurrentTime("foo")); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }