use of zipkin2.proto3.Span in project brave by openzipkin.
the class MutableSpanMapTest method reportOrphanedSpans_afterGC.
/**
* This is the key feature. Spans orphaned via GC are reported to zipkin on the next action.
*
* <p>This is a customized version of https://github.com/raphw/weak-lock-free/blob/master/src/test/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMapTest.java
*/
@Test
public void reportOrphanedSpans_afterGC() {
TraceContext context1 = context.toBuilder().spanId(1).build();
map.getOrCreate(context1);
TraceContext context2 = context.toBuilder().spanId(2).build();
map.getOrCreate(context2);
TraceContext context3 = context.toBuilder().spanId(3).build();
map.getOrCreate(context3);
TraceContext context4 = context.toBuilder().spanId(4).build();
map.getOrCreate(context4);
// By clearing strong references in this test, we are left with the weak ones in the map
context1 = context2 = null;
blockOnGC();
// After GC, we expect that the weak references of context1 and context2 to be cleared
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(null, null, context3, context4);
map.reportOrphanedSpans();
// After reporting, we expect no the weak references of null
assertThat(map.delegate.keySet()).extracting(o -> ((Reference) o).get()).containsExactlyInAnyOrder(context3, context4);
// We also expect the spans to have been reported
assertThat(spans).flatExtracting(Span::annotations).extracting(Annotation::value).containsExactly("brave.flush", "brave.flush");
}
use of zipkin2.proto3.Span in project spring-cloud-gcp by spring-cloud.
the class LabelExtractor method extract.
/**
* Extracts the Stackdriver span labels that are equivalent to the Zipkin Span
* annotations.
*
* @param zipkinSpan The Zipkin Span
* @return A map of the Stackdriver span labels equivalent to the Zipkin annotations.
*/
public Map<String, String> extract(Span zipkinSpan) {
Map<String, String> result = new LinkedHashMap<>();
for (Map.Entry<String, String> tag : zipkinSpan.tags().entrySet()) {
result.put(label(tag.getKey()), tag.getValue());
}
// trace might not show the final destination.
if (zipkinSpan.localEndpoint() != null && zipkinSpan.kind() == Span.Kind.SERVER) {
if (zipkinSpan.localEndpoint().ipv4() != null) {
result.put(label("endpoint.ipv4"), zipkinSpan.localEndpoint().ipv4());
}
if (zipkinSpan.localEndpoint().ipv6() != null) {
result.put(label("endpoint.ipv6"), zipkinSpan.localEndpoint().ipv6());
}
}
for (Annotation annotation : zipkinSpan.annotations()) {
result.put(label(annotation.value()), formatTimestamp(annotation.timestamp()));
}
if (zipkinSpan.localEndpoint() != null && !zipkinSpan.localEndpoint().serviceName().isEmpty()) {
result.put("/component", zipkinSpan.localEndpoint().serviceName());
}
if (zipkinSpan.parentId() == null) {
String agentName = System.getProperty("stackdriver.trace.zipkin.agent", "spring-cloud-gcp-trace");
result.put("/agent", agentName);
}
return result;
}
use of zipkin2.proto3.Span in project spring-cloud-gcp by spring-cloud.
the class LabelExtractorTests method testRpcClientBasics.
@Test
public void testRpcClientBasics() {
LabelExtractor extractor = new LabelExtractor();
String instanceId = "localhost";
long begin = 1238912378081L;
long end = 1238912378123L;
Span span = Span.newBuilder().traceId("123").id("9999").timestamp(begin).duration(end - begin).putTag("http.host", "localhost").putTag("custom-tag", "hello").localEndpoint(Endpoint.newBuilder().serviceName("hello-service").build()).build();
Map<String, String> labels = extractor.extract(span);
Assert.assertNotNull("span shouldn't be null", span);
Assert.assertEquals("localhost", labels.get("/http/host"));
Assert.assertEquals("spring-cloud-gcp-trace", labels.get("/agent"));
Assert.assertEquals("hello-service", labels.get("/component"));
Assert.assertEquals("hello", labels.get("cloud.spring.io/custom-tag"));
}
use of zipkin2.proto3.Span 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 zipkin2.proto3.Span in project spring-cloud-sleuth by spring-cloud.
the class WebClientDiscoveryExceptionTests method shouldCloseSpanUponException.
// issue #240
private void shouldCloseSpanUponException(ResponseEntityProvider provider) throws IOException, InterruptedException {
Span span = this.tracer.nextSpan().name("new trace");
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span.start())) {
provider.get(this);
Assertions.fail("should throw an exception");
} catch (RuntimeException e) {
} finally {
span.finish();
}
// hystrix commands should finish at this point
Thread.sleep(200);
List<zipkin2.Span> spans = this.reporter.getSpans();
then(spans).hasSize(2);
then(spans.stream().filter(span1 -> span1.kind() == zipkin2.Span.Kind.CLIENT).findFirst().get().tags()).containsKey("error");
}
Aggregations