use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.
the class TraceTranslatorTest method testMultihostServerRootSpan_noTimestamp.
@Test
public void testMultihostServerRootSpan_noTimestamp() {
Span span1 = Span.newBuilder().kind(Kind.SERVER).traceId("1").id("1").name("/a").build();
Span span2 = Span.newBuilder().kind(Kind.CLIENT).traceId("1").parentId("1").id("2").name("/b?client").build();
Span span3 = Span.newBuilder().kind(Kind.SERVER).shared(true).traceId("1").parentId("1").id("2").name("/b?server").build();
Span span4 = Span.newBuilder().traceId("1").parentId("2").id("3").name("custom-span").build();
Collection<Trace> traces = TraceTranslator.translateSpans("test-project", Arrays.asList(span1, span2, span3, span4));
assertEquals(1, traces.size());
Trace trace = traces.iterator().next();
Map<String, TraceSpan> spansByName = getSpansByName(trace);
assertThat(spansByName).containsOnlyKeys("/a", "/b?client", "/b?server", "custom-span");
assertDistinctSpanIds(trace);
assertThat(spansByName.get("custom-span").getParentSpanId()).isEqualTo(spansByName.get("/b?server").getSpanId());
assertThat(spansByName.get("/b?server").getParentSpanId()).isEqualTo(spansByName.get("/b?client").getSpanId());
assertThat(spansByName.get("/b?client").getParentSpanId()).isEqualTo(spansByName.get("/a").getSpanId());
// Without the timestamp field, it's not possible to correctly set the root span's parentSpanId
// to 0 because we didn't have enough information to conclude that it had no parent.
}
use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.
the class StackdriverEncoderTest method assertTraceIdPrefixedSpan.
void assertTraceIdPrefixedSpan(byte[] serialized, String expectedTraceId) throws Exception {
char[] traceId = new char[32];
for (int i = 0; i < 32; i++) traceId[i] = (char) serialized[i];
assertThat(new String(traceId)).isEqualTo(expectedTraceId);
TraceSpan deserialized = TraceSpan.parser().parseFrom(serialized, 32, serialized.length - 32);
assertThat(deserialized).isEqualTo(SpanTranslator.translate(TraceSpan.newBuilder(), zipkinSpan).build());
}
use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.
the class SpanTranslator method translate.
/**
* Converts a Zipkin Span into a Stackdriver Trace Span.
*
* Ex.
* <pre>{@code
* traceSpan = SpanTranslator.translate(TraceSpan.newBuilder(), zipkinSpan).build();
* }</pre>
*
* <p>Note: the result does not include the trace ID from the input.
*
* @param spanBuilder the builder (to facilitate re-use)
* @param zipkinSpan The Zipkin Span.
* @return A Stackdriver Trace Span.
*/
public static TraceSpan.Builder translate(TraceSpan.Builder spanBuilder, Span zipkinSpan) {
spanBuilder.setName(zipkinSpan.name() != null ? zipkinSpan.name() : "");
SpanKind kind = getSpanKind(zipkinSpan.kind());
spanBuilder.setKind(kind);
rewriteIds(zipkinSpan, spanBuilder, kind);
if (zipkinSpan.timestampAsLong() != 0L) {
spanBuilder.setStartTime(createTimestamp(zipkinSpan.timestampAsLong()));
if (zipkinSpan.durationAsLong() != 0L) {
Timestamp endTime = createTimestamp(zipkinSpan.timestampAsLong() + zipkinSpan.durationAsLong());
spanBuilder.setEndTime(endTime);
}
}
spanBuilder.putAllLabels(labelExtractor.extract(zipkinSpan));
return spanBuilder;
}
use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.
the class SpanTranslatorTest method translate_missingName.
@Test
public void translate_missingName() {
Span zipkinSpan = Span.newBuilder().traceId("3").id("2").build();
TraceSpan translated = SpanTranslator.translate(TraceSpan.newBuilder(), zipkinSpan).build();
assertThat(translated.getName()).isEqualTo(TraceSpan.getDefaultInstance().getName()).isEmpty();
}
use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.
the class TraceTranslatorTest method testMultihostClientRootSpan_noTimestamp.
@Test
public void testMultihostClientRootSpan_noTimestamp() {
Span span1 = Span.newBuilder().kind(Kind.CLIENT).traceId("1").id("1").name("/a?client").build();
Span span2 = Span.newBuilder().kind(Kind.SERVER).shared(true).traceId("1").id("1").name("/a?server").build();
Span span3 = Span.newBuilder().kind(Kind.CLIENT).traceId("1").parentId("1").id("2").name("/b?client").build();
Span span4 = Span.newBuilder().kind(Kind.SERVER).shared(true).traceId("1").parentId("1").id("2").name("/b?server").build();
Span span5 = Span.newBuilder().traceId("1").parentId("2").id("3").name("custom-span").build();
Collection<Trace> traces = TraceTranslator.translateSpans("test-project", Arrays.asList(span1, span2, span3, span4, span5));
assertEquals(1, traces.size());
Trace trace = traces.iterator().next();
Map<String, TraceSpan> spansByName = getSpansByName(trace);
assertThat(spansByName).containsOnlyKeys("/a?client", "/a?server", "/b?client", "/b?server", "custom-span");
assertDistinctSpanIds(trace);
assertThat(spansByName.get("custom-span").getParentSpanId()).isEqualTo(spansByName.get("/b?server").getSpanId());
assertThat(spansByName.get("/b?server").getParentSpanId()).isEqualTo(spansByName.get("/b?client").getSpanId());
assertThat(spansByName.get("/b?client").getParentSpanId()).isEqualTo(spansByName.get("/a?server").getSpanId());
assertThat(spansByName.get("/a?server").getParentSpanId()).isEqualTo(spansByName.get("/a?client").getSpanId());
assertThat(spansByName.get("/a?client").getParentSpanId()).isEqualTo(0);
}
Aggregations