diff --git a/spring-cloud-sleuth-zipkin-stream/src/test/java/org/springframework/cloud/sleuth/zipkin/stream/ZipkinMessageListenerTests.java b/spring-cloud-sleuth-zipkin-stream/src/test/java/org/springframework/cloud/sleuth/zipkin/stream/ZipkinMessageListenerTests.java index cab8523df..31d94b3ec 100644 --- a/spring-cloud-sleuth-zipkin-stream/src/test/java/org/springframework/cloud/sleuth/zipkin/stream/ZipkinMessageListenerTests.java +++ b/spring-cloud-sleuth-zipkin-stream/src/test/java/org/springframework/cloud/sleuth/zipkin/stream/ZipkinMessageListenerTests.java @@ -34,18 +34,37 @@ public class ZipkinMessageListenerTests { .ipv4(1 << 24 | 2 << 16 | 3 << 8 | 4) .port(8080).build(); - /** Sleuth timestamps are millisecond granularity while zipkin is microsecond. */ + /** + * In the RPC span model, the client owns the timestamp and duration of the span. If we + * were propagated an id, we can assume that we shouldn't report timestamp or duration, + * rather let the client do that. Worst case we were propagated an unreported ID and + * Zipkin backfills timestamp and duration. + */ @Test - public void convertsTimestampAndDurationToMicroseconds() { - long start = System.currentTimeMillis(); - this.span.logEvent("hystrix/retry"); // System.currentTimeMillis - + public void doesntSetTimestampOrDurationWhenRemote() { + this.span.stop(); zipkin.Span result = ConvertToZipkinSpanList.convert(this.span, this.host); assertThat(result.timestamp) - .isEqualTo(this.span.getBegin() * 1000); + .isNull(); assertThat(result.duration) - .isEqualTo((this.span.getEnd() - this.span.getBegin()) * 1000); + .isNull(); + } + + /** Sleuth timestamps are millisecond granularity while zipkin is microsecond. */ + @Test + public void convertsTimestampAndDurationToMicroseconds() { + Span span = new Span(1, 3, "http:name", 1L, Collections.emptyList(), 2L, false, true, + "process"); + long start = System.currentTimeMillis(); + span.logEvent("hystrix/retry"); // System.currentTimeMillis + + zipkin.Span result = ConvertToZipkinSpanList.convert(span, this.host); + + assertThat(result.timestamp) + .isEqualTo(span.getBegin() * 1000); + assertThat(result.duration) + .isEqualTo((span.getEnd() - span.getBegin()) * 1000); assertThat(result.annotations.get(0).timestamp) .isGreaterThanOrEqualTo(start * 1000) .isLessThanOrEqualTo(System.currentTimeMillis() * 1000);