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