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);
});
}
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());
}
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());
}
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());
}
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);
}
Aggregations