Search in sources :

Example 11 with TraceSpan

use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.

the class TraceTranslatorTest method testSinglehostClientRootSpan.

@Test
public void testSinglehostClientRootSpan() {
    Span span1 = Span.newBuilder().traceId("1").id("1").name("/a?client").timestamp(// This is set because the client owns the span
    1474488796000000L).duration(5000000L).build();
    Span span2 = Span.newBuilder().traceId("1").parentId("1").id("2").name("/a?server").timestamp(1474488796000000L).duration(5000000L).build();
    Span span3 = Span.newBuilder().traceId("1").parentId("2").id("3").name("/b?client").timestamp(// This is set because the client owns the span.
    1474488797000000L).duration(1500000L).build();
    Span span4 = Span.newBuilder().traceId("1").parentId("3").id("4").name("/b?server").timestamp(1474488797500000L).duration(800000L).build();
    Span span5 = Span.newBuilder().traceId("1").parentId("4").id("5").name("custom-span").timestamp(1474488797600000L).duration(200000L).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);
}
Also used : Trace(com.google.devtools.cloudtrace.v1.Trace) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test)

Example 12 with TraceSpan

use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.

the class TraceTranslatorTest method testMultihostClientRootSpan.

@Test
public void testMultihostClientRootSpan() {
    Span span1 = Span.newBuilder().kind(Kind.CLIENT).traceId("1").id("1").name("/a?client").timestamp(// This is set because the client owns the span
    1474488796000000L).duration(5000000L).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").timestamp(// This is set because the client owns the span.
    1474488797000000L).duration(1500000L).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").timestamp(1474488797600000L).duration(200000L).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);
}
Also used : Trace(com.google.devtools.cloudtrace.v1.Trace) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test)

Example 13 with TraceSpan

use of com.google.devtools.cloudtrace.v1.TraceSpan in project zipkin-gcp by openzipkin.

the class TracesParser method nextSpan.

@Override
public void nextSpan(byte[] traceIdPrefixedSpan) {
    TraceSpan traceSpan = parseTraceIdPrefixedSpan(traceIdPrefixedSpan);
    currentTrace.addSpans(traceSpan);
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan)

Example 14 with TraceSpan

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

the class StackdriverTraceReporter method report.

@Override
public void report(Span span) {
    TraceSpan traceSpan = this.spanTranslator.translate(span);
    Traces traces = Traces.newBuilder().addTraces(Trace.newBuilder().setTraceId(padTraceId(span.traceId())).setProjectId(this.projectId).addSpans(traceSpan).build()).build();
    this.traceConsumer.receive(traces);
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Traces(com.google.devtools.cloudtrace.v1.Traces)

Example 15 with TraceSpan

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

the class StackdriverTraceReporterTests method testSingleServerSpan.

@Test
public void testSingleServerSpan() {
    Span parent = Span.newBuilder().traceId("123").id("9999").name("http:parent").timestamp(beginTime).duration(endTime - beginTime).kind(Span.Kind.SERVER).build();
    this.reporter.report(parent);
    Assert.assertEquals(1, this.test.traceSpans.size());
    TraceSpan traceSpan = this.test.traceSpans.get(0);
    Assert.assertEquals("http:parent", traceSpan.getName());
    // Server Spans should use Span begin and end time, not SR or SS
    Assert.assertEquals(this.spanTranslator.createTimestamp(beginTime), traceSpan.getStartTime());
    Assert.assertEquals(this.spanTranslator.createTimestamp(endTime), traceSpan.getEndTime());
    Assert.assertEquals(TraceSpan.SpanKind.RPC_SERVER, traceSpan.getKind());
}
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