Search in sources :

Example 1 with TraceSpan

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

the class StackdriverTraceAutoConfigurationTests method test.

@Test
public void test() {
    this.contextRunner.run(context -> {
        SleuthProperties sleuthProperties = context.getBean(SleuthProperties.class);
        assertThat(sleuthProperties.isTraceId128()).isTrue();
        assertThat(sleuthProperties.isSupportsJoin()).isFalse();
        Reporter<zipkin2.Span> reporter = context.getBean(Reporter.class);
        assertThat(reporter).isInstanceOf(StackdriverTraceReporter.class);
        Tracer tracer = context.getBean(Tracer.class);
        Span span = tracer.newTrace().start().kind(Span.Kind.CLIENT).name("test").start();
        span.finish();
        // There should be one trace received
        MockConfiguration configuration = context.getBean(MockConfiguration.class);
        assertThat(configuration.tracesList.size()).isEqualTo(1);
        Traces traces = configuration.tracesList.get(0);
        assertThat(traces.getTracesCount()).isEqualTo(1);
        Trace trace = traces.getTraces(0);
        assertThat(trace.getSpansCount()).isEqualTo(1);
        TraceSpan traceSpan = trace.getSpans(0);
    });
}
Also used : Trace(com.google.devtools.cloudtrace.v1.Trace) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) SleuthProperties(org.springframework.cloud.sleuth.autoconfig.SleuthProperties) Traces(com.google.devtools.cloudtrace.v1.Traces) Tracer(brave.Tracer) Span(brave.Span) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Test(org.junit.Test)

Example 2 with TraceSpan

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

the class StackdriverTraceReporterTests method testSingleClientSpan.

@Test
public void testSingleClientSpan() {
    Span parent = Span.newBuilder().traceId("123").id("9999").name("http:call").timestamp(beginTime).duration(endTime - beginTime).kind(Span.Kind.CLIENT).build();
    this.reporter.report(parent);
    Assert.assertEquals(1, this.test.traceSpans.size());
    TraceSpan traceSpan = this.test.traceSpans.get(0);
    Assert.assertEquals("http:call", traceSpan.getName());
    // Client span chould use CS and CR time, not Span begin or end time.
    Assert.assertEquals(this.spanTranslator.createTimestamp(beginTime), traceSpan.getStartTime());
    Assert.assertEquals(this.spanTranslator.createTimestamp(endTime), traceSpan.getEndTime());
    Assert.assertEquals(TraceSpan.SpanKind.RPC_CLIENT, 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)

Example 3 with TraceSpan

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

the class SpanTranslatorTest method translate_clientSpan.

/**
 * This test is intentionally sensitive, so changing other parts makes obvious impact here
 */
@Test
public void translate_clientSpan() {
    Span zipkinSpan = Span.newBuilder().traceId("7180c278b62e8f6a216a2aea45d08fc9").parentId("6b221d5bc9e6496c").id("5b4185666d50f68b").name("get").kind(Span.Kind.CLIENT).localEndpoint(Endpoint.newBuilder().serviceName("frontend").build()).remoteEndpoint(Endpoint.newBuilder().serviceName("backend").ip("192.168.99.101").port(9000).build()).timestamp(// 1 second after epoch
    1_000_000L).duration(123_456L).addAnnotation(1_123_000L, "foo").putTag("http.path", "/api").putTag("clnt/finagle.version", "6.45.0").build();
    TraceSpan translated = SpanTranslator.translate(TraceSpan.newBuilder(), zipkinSpan).build();
    assertThat(translated).isEqualTo(TraceSpan.newBuilder().setSpanId(Long.parseUnsignedLong(zipkinSpan.id(), 16) ^ 0x3f6a2ec3c810c2abL).setParentSpanId(Long.parseUnsignedLong(zipkinSpan.parentId(), 16)).setKind(TraceSpan.SpanKind.RPC_CLIENT).setName("get").setStartTime(Timestamp.newBuilder().setSeconds(1).build()).setEndTime(Timestamp.newBuilder().setSeconds(1).setNanos(123_456_000).build()).putLabels("zipkin.io/clnt/finagle.version", "6.45.0").putLabels("zipkin.io/http.path", "/api").putLabels("/component", "frontend").putLabels("zipkin.io/foo", "1970-01-01 (00:00:01.123)").build());
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) Span(zipkin2.Span) Test(org.junit.Test)

Example 4 with TraceSpan

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

the class TraceTranslatorTest method assertDistinctSpanIds.

private static void assertDistinctSpanIds(Trace trace) {
    Set<Long> spanIds = new HashSet<>();
    for (TraceSpan span : trace.getSpansList()) {
        spanIds.add(span.getSpanId());
    }
    assertEquals("Trace does not have enough distinct span IDs", trace.getSpansCount(), spanIds.size());
}
Also used : TraceSpan(com.google.devtools.cloudtrace.v1.TraceSpan) HashSet(java.util.HashSet)

Example 5 with TraceSpan

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

the class TraceTranslatorTest method testMultihostServerRootSpan.

@Test
public void testMultihostServerRootSpan() {
    Span span1 = Span.newBuilder().traceId("1").id("1").name("/a").timestamp(// This is set because the server owns the span
    1474488796000000L).duration(5000000L).build();
    Span span2 = 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 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").timestamp(1474488797600000L).duration(200000L).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());
    assertThat(spansByName.get("/a").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)

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