Search in sources :

Example 36 with Span

use of io.opencensus.proto.trace.v1.Span 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.
}
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 37 with Span

use of io.opencensus.proto.trace.v1.Span in project spring-cloud-gcp by spring-cloud.

the class StackdriverTraceAutoConfiguration method stackdriverReporter.

@Bean(REPORTER_BEAN_NAME)
@ConditionalOnMissingBean(name = REPORTER_BEAN_NAME)
public Reporter<Span> stackdriverReporter(ReporterMetrics reporterMetrics, GcpTraceProperties trace, @Qualifier(SENDER_BEAN_NAME) Sender sender) {
    AsyncReporter<Span> asyncReporter = AsyncReporter.builder(sender).queuedMaxSpans(1000).messageTimeout(trace.getMessageTimeout(), TimeUnit.SECONDS).metrics(reporterMetrics).build(StackdriverEncoder.V2);
    CheckResult checkResult = asyncReporter.check();
    if (!checkResult.ok()) {
        LOGGER.warn("Error when performing Stackdriver AsyncReporter health check.", checkResult.error());
    }
    return asyncReporter;
}
Also used : CheckResult(zipkin2.CheckResult) Span(zipkin2.Span) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 38 with Span

use of io.opencensus.proto.trace.v1.Span in project spring-cloud-gcp by spring-cloud.

the class StackdriverTraceAutoConfigurationTests method testAsyncReporterHealthCheck.

@Test
public void testAsyncReporterHealthCheck() {
    Sender senderMock = mock(Sender.class);
    when(senderMock.check()).thenReturn(CheckResult.OK);
    when(senderMock.encoding()).thenReturn(SpanBytesEncoder.PROTO3.encoding());
    this.contextRunner.withBean(StackdriverTraceAutoConfiguration.SENDER_BEAN_NAME, Sender.class, () -> senderMock).run(context -> {
        Reporter<Span> asyncReporter = context.getBean(Reporter.class);
        assertThat(asyncReporter).isNotNull();
        verify(senderMock, times(1)).check();
    });
}
Also used : Sender(zipkin2.reporter.Sender) Span(com.google.devtools.cloudtrace.v2.Span) Test(org.junit.Test)

Example 39 with Span

use of io.opencensus.proto.trace.v1.Span in project curiostack by curioswitch.

the class StackdriverReporter method flush.

@Override
public void flush() {
    List<Span> spans = new ArrayList<>(queue.size());
    queue.drain(spans::add);
    if (spans.isEmpty()) {
        return;
    }
    List<com.google.devtools.cloudtrace.v2.Span> translated = SpanTranslator.translate(projectId, spans);
    BatchWriteSpansRequest request = BatchWriteSpansRequest.newBuilder().setName("projects/" + projectId).addAllSpans(translated).build();
    Futures.addCallback(traceServiceClient.get().batchWriteSpans(request), new FutureCallback<Empty>() {

        @Override
        public void onFailure(Throwable t) {
            logger.warn("Error reporting traces.", t);
        }

        @Override
        public void onSuccess(Empty result) {
            logger.trace("Successfully reported traces.");
        }
    }, MoreExecutors.directExecutor());
}
Also used : BatchWriteSpansRequest(com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest) Empty(com.google.protobuf.Empty) ArrayList(java.util.ArrayList) Span(zipkin2.Span)

Example 40 with Span

use of io.opencensus.proto.trace.v1.Span in project spring-cloud-sleuth by spring-cloud.

the class TraceFilterWebIntegrationTests method should_not_create_a_span_for_error_controller.

@Test
public void should_not_create_a_span_for_error_controller() {
    try {
        new RestTemplate().getForObject("http://localhost:" + port() + "/", String.class);
        BDDAssertions.fail("should fail due to runtime exception");
    } catch (Exception e) {
    }
    then(Tracing.current().tracer().currentSpan()).isNull();
    then(this.accumulator.getSpans()).hasSize(1);
    Span fromFirstTraceFilterFlow = this.accumulator.getSpans().get(0);
    then(fromFirstTraceFilterFlow.tags()).containsEntry("http.status_code", "500").containsEntry("http.method", "GET").containsEntry("mvc.controller.class", "ExceptionThrowingController").containsEntry("error", "Request processing failed; nested exception is java.lang.RuntimeException: Throwing exception");
    // issue#714
    String hex = fromFirstTraceFilterFlow.traceId();
    String[] split = capture.toString().split("\n");
    List<String> list = Arrays.stream(split).filter(s -> s.contains("Uncaught exception thrown")).filter(s -> s.contains(hex + "," + hex + ",true]")).collect(Collectors.toList());
    then(list).isNotEmpty();
}
Also used : BDDAssertions(org.assertj.core.api.BDDAssertions) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Span(zipkin2.Span) DefaultResponseErrorHandler(org.springframework.web.client.DefaultResponseErrorHandler) Sampler(brave.sampler.Sampler) After(org.junit.After) ArrayListSpanReporter(org.springframework.cloud.sleuth.util.ArrayListSpanReporter) SpringRunner(org.springframework.test.context.junit4.SpringRunner) OutputCapture(org.springframework.boot.test.rule.OutputCapture) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) RestTemplate(org.springframework.web.client.RestTemplate) Before(org.junit.Before) HttpAdapter(brave.http.HttpAdapter) Tracing(brave.Tracing) HttpSampler(brave.http.HttpSampler) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) IOException(java.io.IOException) Test(org.junit.Test) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) Configuration(org.springframework.context.annotation.Configuration) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) List(java.util.List) Rule(org.junit.Rule) Assertions.fail(org.assertj.core.api.Assertions.fail) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Environment(org.springframework.core.env.Environment) ResponseEntity(org.springframework.http.ResponseEntity) Pattern(java.util.regex.Pattern) Bean(org.springframework.context.annotation.Bean) RestTemplate(org.springframework.web.client.RestTemplate) Span(zipkin2.Span) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Span (zipkin2.Span)290 Test (org.junit.Test)192 Test (org.junit.jupiter.api.Test)67 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)41 Endpoint (zipkin2.Endpoint)37 ArrayList (java.util.ArrayList)24 V1Span (zipkin2.v1.V1Span)17 List (java.util.List)14 AggregateCall (zipkin2.internal.AggregateCall)13 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)12 Arrays.asList (java.util.Arrays.asList)9 Map (java.util.Map)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 Span (com.google.devtools.cloudtrace.v2.Span)8 LinkedHashMap (java.util.LinkedHashMap)8 Trace (com.google.devtools.cloudtrace.v1.Trace)7 Span (zipkin2.proto3.Span)7 SpanData (io.opencensus.trace.export.SpanData)6 SpanCustomizer (brave.SpanCustomizer)5 IOException (java.io.IOException)5