Search in sources :

Example 16 with TraceSpan

use of com.google.devtools.cloudtrace.v1.TraceSpan in project spring-cloud-gcp by spring-cloud.

the class StackdriverTraceReporterTests method testClientServerSpans.

@Test
public void testClientServerSpans() {
    Span clientSpan = Span.newBuilder().traceId("123").id("9999").name("http:call").timestamp(beginTime).duration(endTime - beginTime).kind(Span.Kind.CLIENT).build();
    Span serverSpan = Span.newBuilder().traceId("123").parentId(clientSpan.id()).id(clientSpan.id()).name("http:service").timestamp(beginTime).duration(endTime - beginTime).kind(Span.Kind.SERVER).build();
    this.reporter.report(serverSpan);
    this.reporter.report(clientSpan);
    Assert.assertEquals(2, this.test.traceSpans.size());
    TraceSpan serverTraceSpan = this.test.traceSpans.get(0);
    Assert.assertEquals("http:service", serverTraceSpan.getName());
    Assert.assertEquals(TraceSpan.SpanKind.RPC_SERVER, serverTraceSpan.getKind());
    TraceSpan clientTraceSpan = this.test.traceSpans.get(1);
    Assert.assertEquals("http:call", clientTraceSpan.getName());
    // Client span chould use CS and CR time, not Span begin or end time.
    Assert.assertEquals(this.spanTranslator.createTimestamp(beginTime), clientTraceSpan.getStartTime());
    Assert.assertEquals(this.spanTranslator.createTimestamp(endTime), clientTraceSpan.getEndTime());
    Assert.assertEquals(TraceSpan.SpanKind.RPC_CLIENT, clientTraceSpan.getKind());
    Assert.assertEquals(0, clientTraceSpan.getParentSpanId());
    Assert.assertNotEquals(Long.valueOf(serverSpan.parentId()).longValue(), serverTraceSpan.getParentSpanId());
    // Even though the client and server spans shared the same Span ID. In Stackdriver Trace,
    // the IDs should be different. This is accomplished through
    // StackdriverTraceSpanListener.rewriteIds().
    Assert.assertNotEquals(clientTraceSpan.getSpanId(), serverTraceSpan.getSpanId());
    // Although the Span IDs were re-written, the server Span's parent ID should still refer
    // to client Span ID.
    Assert.assertEquals(serverTraceSpan.getParentSpanId(), clientTraceSpan.getSpanId());
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)15 Test (org.junit.Test)11 Span (zipkin2.Span)10 Trace (com.google.devtools.cloudtrace.v1.Trace)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Traces (com.google.devtools.cloudtrace.v1.Traces)2 Span (brave.Span)1 Tracer (brave.Tracer)1 SpanKind (com.google.devtools.cloudtrace.v1.TraceSpan.SpanKind)1 Timestamp (com.google.protobuf.Timestamp)1 HashSet (java.util.HashSet)1 SleuthProperties (org.springframework.cloud.sleuth.autoconfig.SleuthProperties)1