Skip to content

Commit 9a8e7d5

Browse files
authored
Lack of timestamp in server-only spans implies shared (openzipkin#1690)
When "sr" is present without a timestamp, we assume this is a shared span. Moving this signal to the converter allows stackdriver-zipkin to reuse this when converting to their single-host types. See openzipkin/openzipkin.github.io#49
1 parent 69fba38 commit 9a8e7d5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

zipkin/src/main/java/zipkin/internal/Span2Converter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ void processAnnotations(Span source) {
131131
}
132132
}
133133

134+
// Span v1 format did not have a shared flag. By convention, span.timestamp being absent
135+
// implied shared. When we only see the server-side, carry this signal over.
136+
if (cs == null && (sr != null && source.timestamp == null)) {
137+
forEndpoint(source, sr.endpoint).shared(true);
138+
}
139+
134140
// ms and mr are not supposed to be in the same span, but in case they are..
135141
if (ms != null && mr != null) {
136142
// special-case loopback: We need to make sure on loopback there are two span2s

zipkin/src/test/java/zipkin/internal/Span2ConverterTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,37 @@ public class Span2ConverterTest {
361361
.containsExactly(client, server);
362362
}
363363

364+
/**
365+
* The old span format had no means of saying it is shared or not. This uses lack of timestamp as
366+
* a signal
367+
*/
368+
@Test public void assumesServerWithoutTimestampIsShared() {
369+
Span span = Span.builder()
370+
.traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a"))
371+
.traceId(Util.lowerHexToUnsignedLong("216a2aea45d08fc9"))
372+
.parentId(Util.lowerHexToUnsignedLong("6b221d5bc9e6496c"))
373+
.id(Util.lowerHexToUnsignedLong("5b4185666d50f68b"))
374+
.name("get")
375+
.addAnnotation(Annotation.create(1472470996250000L, Constants.SERVER_RECV, backend))
376+
.addAnnotation(Annotation.create(1472470996350000L, Constants.SERVER_SEND, backend))
377+
.build();
378+
379+
Span2 span2 = Span2.builder()
380+
.traceId("7180c278b62e8f6a216a2aea45d08fc9")
381+
.parentId("6b221d5bc9e6496c")
382+
.id("5b4185666d50f68b")
383+
.name("get")
384+
.kind(Kind.SERVER)
385+
.shared(true)
386+
.localEndpoint(backend)
387+
.timestamp(1472470996250000L)
388+
.duration(100000L)
389+
.build();
390+
391+
assertThat(Span2Converter.fromSpan(span))
392+
.containsExactly(span2);
393+
}
394+
364395
@Test public void clientAndServer_loopback() {
365396
Span shared = Span.builder()
366397
.traceIdHigh(Util.lowerHexToUnsignedLong("7180c278b62e8f6a"))

0 commit comments

Comments
 (0)