private Span createFilledOutSpan( boolean completed, Map<String, String> tags, List<TimestampedAnnotation> annotations ) { Long durationNanos = (completed) ? durationNanosForFullyCompletedSpan : null; return new Span( traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId, spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan, startTimeNanosForFullyCompleteSpan, durationNanos, tags, annotations ); }
private Span createFilledOutSpan(boolean completed) { Long durationNanos = (completed) ? durationNanosForFullyCompletedSpan : null; return new Span(traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId, spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan, startTimeNanosForFullyCompleteSpan, durationNanos, tags, annotations ); }
return new Span( traceId, parentSpanId, spanId, spanName, sampleable, userId, spanPurpose, spanStartTimeEpochMicros, spanStartTimeNanos, durationNanos, tags, annotations
@Test(expected = IllegalArgumentException.class) public void public_constructor_throws_IllegalArgumentException_if_passed_null_span_id() { // expect new Span(traceId, parentSpanId, null, spanName, true, userId, spanPurpose, 42, null, null, null, null); }
@Test(expected = IllegalArgumentException.class) public void public_constructor_throws_IllegalArgumentException_if_passed_null_span_name() { // expect new Span(traceId, parentSpanId, spanId, null, true, userId, spanPurpose, 42, null, null, null, null); }
@Test(expected = IllegalArgumentException.class) public void public_constructor_throws_IllegalArgumentException_if_passed_null_trace_id() { // expect new Span(null, parentSpanId, spanId, spanName, true, userId, spanPurpose, 42, null, null, null, null); }
@Test public void protected_constructor_generates_instance_with_placeholder_values() { // given String placeholderValue = "PLACEHOLDER"; // when Span result = new Span(); // then verifySpanDeepEquals( result, new Span( placeholderValue, null, placeholderValue, placeholderValue, false, null, SpanPurpose.UNKNOWN, -1, -1L, -1L, null, null ), false ); }
@Test public void public_constructor_defaults_to_UNKNOWN_span_purpose_if_passed_null() { // when Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null); // then assertThat(span.getSpanPurpose()).isEqualTo(SpanPurpose.UNKNOWN); }
@Test public void public_constructor_calculates_start_time_nanos_if_passed_null() { // given long startTimeEpochMicrosUsed = 42; long nanosBeforeCall = System.nanoTime(); long epochMicrosBeforeCall = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); // when Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, spanPurpose, startTimeEpochMicrosUsed, null, 41L, null, null); long epochMicrosAfterCall = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); long nanosAfterCall = System.nanoTime(); // then long lowerBound = calculateNanoStartTimeFromSpecifiedEpochMicrosStartTime(startTimeEpochMicrosUsed, epochMicrosBeforeCall, nanosBeforeCall); long upperBound = calculateNanoStartTimeFromSpecifiedEpochMicrosStartTime(startTimeEpochMicrosUsed, epochMicrosAfterCall, nanosAfterCall); assertThat(span.getSpanStartTimeNanos()).isBetween(lowerBound, upperBound); }
@Test public void convertWingtipsSpanToZipkinSpan_works_as_expected_for_128_bit_trace_id() { // given String high64Bits = "463ac35c9f6413ad"; String low64Bits = "48485a3953bb6124"; String hex128Bits = high64Bits + low64Bits; String spanName = UUID.randomUUID().toString(); String traceId = hex128Bits; String spanId = low64Bits; long startTimeEpochMicros = Math.abs(random.nextLong()); long durationNanos = Math.abs(random.nextLong()); Endpoint zipkinEndpoint = Endpoint.create(UUID.randomUUID().toString(), 42); String localComponentNamespace = UUID.randomUUID().toString(); Map<String,String> tags = createSingleTagMap(); List<TimestampedAnnotation> annotations = createSingleTimestampedAnnotationList(); Span wingtipsSpan = new Span( traceId, null, spanId, spanName, true, null, Span.SpanPurpose.CLIENT, startTimeEpochMicros, null, durationNanos, tags, annotations ); // when zipkin.Span zipkinSpan = impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint, localComponentNamespace); // then assertThat(zipkinSpan.traceIdHigh).isEqualTo(unsignedLowerHexStringToLong(high64Bits)); assertThat(zipkinSpan.traceId).isEqualTo(unsignedLowerHexStringToLong(low64Bits)); }
@Test public void public_constructor_uses_empty_annotations_list_when_annotations_argument_is_null() { // when Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null); // then assertThat(span.getTimestampedAnnotations()) .isNotNull() .isEmpty(); }
Map<String,String> tags = createSingleTagMap(); List<TimestampedAnnotation> annotations = createSingleTimestampedAnnotationList(); final Span wingtipsSpan = new Span( traceId, null, spanId, spanName, true, null, Span.SpanPurpose.CLIENT, startTimeEpochMicros, null, durationNanos, tags, annotations
@Test public void public_constructor_uses_empty_tags_map_when_tags_argument_is_null() { // when Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null); // then assertThat(span.getTags()) .isNotNull() .isEmpty(); }
@Test public void public_constructor_works_as_expected_for_completed_span() { // when Span span = new Span( traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId, spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan, startTimeNanosForFullyCompleteSpan, durationNanosForFullyCompletedSpan, tags, annotations ); // then assertThat(span.getTraceId()).isEqualTo(traceId); assertThat(span.getParentSpanId()).isEqualTo(parentSpanId); assertThat(span.getSpanId()).isEqualTo(spanId); assertThat(span.getSpanName()).isEqualTo(spanName); assertThat(span.isSampleable()).isEqualTo(sampleableForFullyCompleteSpan); assertThat(span.getUserId()).isEqualTo(userId); assertThat(span.getSpanStartTimeEpochMicros()).isEqualTo(startTimeEpochMicrosForFullyCompleteSpan); assertThat(span.getSpanStartTimeNanos()).isEqualTo(startTimeNanosForFullyCompleteSpan); assertThat(span.getSpanPurpose()).isEqualTo(spanPurposeForFullyCompletedSpan); assertThat(span.isCompleted()).isTrue(); assertThat(span.getDurationNanos()).isEqualTo(durationNanosForFullyCompletedSpan); assertThat(span.getTags()).isEqualTo(tags); assertThat(span.getTimestampedAnnotations()).isEqualTo(annotations); }
protected static Span fromKeyValueMap( Map<String, String> map, Map<String, String> tags, List<TimestampedAnnotation> annotations ) { // Use the map to get the field values for the span. String traceId = nullSafeGetString(map, TRACE_ID_FIELD); String spanId = nullSafeGetString(map, SPAN_ID_FIELD); String parentSpanId = nullSafeGetString(map, PARENT_SPAN_ID_FIELD); String spanName = nullSafeGetString(map, SPAN_NAME_FIELD); Boolean sampleable = nullSafeGetBoolean(map, SAMPLEABLE_FIELD); if (sampleable == null) { throw new IllegalStateException("Unable to parse " + SAMPLEABLE_FIELD + " from serialized Span"); } String userId = nullSafeGetString(map, USER_ID_FIELD); Long startTimeEpochMicros = nullSafeGetLong(map, START_TIME_EPOCH_MICROS_FIELD); if (startTimeEpochMicros == null) { throw new IllegalStateException( "Unable to parse " + START_TIME_EPOCH_MICROS_FIELD + " from serialized Span" ); } Long durationNanos = nullSafeGetLong(map, DURATION_NANOS_FIELD); SpanPurpose spanPurpose = nullSafeGetSpanPurpose(map, SPAN_PURPOSE_FIELD); return new Span( traceId, parentSpanId, spanId, spanName, sampleable, userId, spanPurpose, startTimeEpochMicros, null, durationNanos, tags, annotations ); }
@Test public void public_constructor_works_as_expected_for_incomplete_span() { // when Span span = new Span( traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId, spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan, startTimeNanosForFullyCompleteSpan, null, tags, annotations ); // then assertThat(span.getTraceId()).isEqualTo(traceId); assertThat(span.getParentSpanId()).isEqualTo(parentSpanId); assertThat(span.getSpanId()).isEqualTo(spanId); assertThat(span.getSpanName()).isEqualTo(spanName); assertThat(span.isSampleable()).isEqualTo(sampleableForFullyCompleteSpan); assertThat(span.getUserId()).isEqualTo(userId); assertThat(span.getSpanStartTimeEpochMicros()).isEqualTo(startTimeEpochMicrosForFullyCompleteSpan); assertThat(span.getSpanStartTimeNanos()).isEqualTo(startTimeNanosForFullyCompleteSpan); assertThat(span.getSpanPurpose()).isEqualTo(spanPurposeForFullyCompletedSpan); assertThat(span.isCompleted()).isFalse(); assertThat(span.getDurationNanos()).isNull(); assertThat(span.getTags()).isEqualTo(tags); assertThat(span.getTimestampedAnnotations()).isEqualTo(annotations); }
long durationMicros = TimeUnit.NANOSECONDS.toMicros(durationNanos); String localComponentNamespace = UUID.randomUUID().toString(); Span wingtipsSpan = new Span( traceId, null, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos, null, null
Map<String,String> tags = createMultipleTagMap(); List<TimestampedAnnotation> annotations = createMultipleTimestampedAnnotationList(); Span wingtipsSpan = new Span( traceId, parentId, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos, tags, annotations
long durationMicros = TimeUnit.NANOSECONDS.toMicros(durationNanos); Endpoint zipkinEndpoint = Endpoint.newBuilder().serviceName(UUID.randomUUID().toString()).build(); Span wingtipsSpan = new Span( traceId, null, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos, null, null
Map<String, String> tags = createMultipleTagMap(); List<TimestampedAnnotation> annotations = createMultipleTimestampedAnnotationList(); Span wingtipsSpan = new Span( traceId, parentId, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos, tags, annotations