Span implements Closeable, Serializable { @Override public String toString() { return toJSON(); } Span(String traceId, String parentSpanId, String spanId, String spanName, boolean sampleable, String userId,
                SpanPurpose spanPurpose, long spanStartTimeEpochMicros, Long spanStartTimeNanos, Long durationNanos,
                Map<String,String> tags, List<TimestampedAnnotation> annotations
    ); protected  Span(); static Builder generateRootSpanForNewTrace(String spanName, SpanPurpose spanPurpose); Span generateChildSpan(String spanName, SpanPurpose spanPurpose); static Builder newBuilder(String spanName, SpanPurpose spanPurpose); static Builder newBuilder(Span copy); String getTraceId(); String getSpanId(); String getParentSpanId(); String getSpanName(); boolean isSampleable(); String getUserId(); long getSpanStartTimeEpochMicros(); long getSpanStartTimeNanos(); SpanPurpose getSpanPurpose(); boolean isCompleted(); Long getDurationNanos(); TracerManagedSpanStatus getCurrentTracerManagedSpanStatus(); Map<String,String> getTags(); void putTag(String key, String value); void removeTag(String key); List<TimestampedAnnotation> getTimestampedAnnotations(); void addTimestampedAnnotationForCurrentTime(String value); void addTimestampedAnnotation(TimestampedAnnotation timestampedAnnotation); @Override String toString(); String toKeyValueString(); String toJSON(); @Override void close(); @Override boolean equals(Object o); @Override int hashCode(); @Deprecated static Span fromKeyValueString(String keyValueStr); @Deprecated static Span fromJSON(String json); @Deprecated
    static final String TRACE_ID_FIELD; @Deprecated
    static final String PARENT_SPAN_ID_FIELD; @Deprecated
    static final String SPAN_ID_FIELD; @Deprecated
    static final String SPAN_NAME_FIELD; @Deprecated
    static final String SAMPLEABLE_FIELD; @Deprecated
    static final String USER_ID_FIELD; @Deprecated
    static final String SPAN_PURPOSE_FIELD; @Deprecated
    static final String START_TIME_EPOCH_MICROS_FIELD; @Deprecated
    static final String DURATION_NANOS_FIELD; }
@DataProvider(value = { "true", "false" }) @Test public void toString_matches_SpanParser_convertSpanToJSON(boolean completed) { Span span = createFilledOutSpan(completed); String jsonFromSpanParser = SpanParser.convertSpanToJSON(span); String toStringFromSpan = span.toString(); assertThat(toStringFromSpan).isEqualTo(jsonFromSpanParser); }
@Test public void TimestampedAnnotation_constructor_works_as_expected() { long timestamp = 42; String value = UUID.randomUUID().toString(); TimestampedAnnotation result = new TimestampedAnnotation(timestamp, value); assertThat(result.getTimestampEpochMicros()).isEqualTo(timestamp); assertThat(result.getValue()).isEqualTo(value); }
@Test public void TimestampedAnnotation_forEpochMicros_works_as_expected() { long timestampMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); String value = UUID.randomUUID().toString(); TimestampedAnnotation result = TimestampedAnnotation.forEpochMicros(timestampMicros, value); assertThat(result.getTimestampEpochMicros()).isEqualTo(timestampMicros); assertThat(result.getValue()).isEqualTo(value); }
@Test public void TimestampedAnnotation_forEpochMillis_works_as_expected() { long timestampMillis = System.currentTimeMillis(); String value = UUID.randomUUID().toString(); TimestampedAnnotation result = TimestampedAnnotation.forEpochMillis(timestampMillis, value); assertThat(result.getTimestampEpochMicros()).isEqualTo(TimeUnit.MILLISECONDS.toMicros(timestampMillis)); assertThat(result.getValue()).isEqualTo(value); }
@Test public void TimestampedAnnotation_forCurrentTime_works_as_expected() { String value = UUID.randomUUID().toString(); long beforeMillis = System.currentTimeMillis(); TimestampedAnnotation result = TimestampedAnnotation.forCurrentTime(value); long afterMillis = System.currentTimeMillis(); long beforeMicros = TimeUnit.MILLISECONDS.toMicros(beforeMillis); long afterMicros = TimeUnit.MILLISECONDS.toMicros(afterMillis); assertThat(result.getTimestampEpochMicros()).isBetween(beforeMicros, afterMicros); assertThat(result.getValue()).isEqualTo(value); }
@Test public void TimestampedAnnotation_forEpochMicrosWithNanoOffset_works_as_expected() { long timestampMicros = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); long nanoOffset = 4242; String value = UUID.randomUUID().toString(); long expectedMicrosOffset = TimeUnit.NANOSECONDS.toMicros(nanoOffset); assertThat(expectedMicrosOffset).isGreaterThan(0); long expectedTimestamp = timestampMicros + expectedMicrosOffset; assertThat(expectedTimestamp).isNotEqualTo(timestampMicros); TimestampedAnnotation result = TimestampedAnnotation.forEpochMicrosWithNanoOffset( timestampMicros, nanoOffset, value ); assertThat(result.getTimestampEpochMicros()).isEqualTo(expectedTimestamp); assertThat(result.getValue()).isEqualTo(value); }