use of zipkin2.Span.Kind.SERVER 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);
}
use of zipkin2.Span.Kind.SERVER 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 zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class ITZipkinGrpcCollector method callReport.
ReportResponse callReport(ListOfSpans spans) throws IOException {
Buffer requestBody = new Buffer();
requestBody.writeByte(0);
Buffer encodedMessage = new Buffer();
ListOfSpans.ADAPTER.encode(encodedMessage, spans);
requestBody.writeInt((int) encodedMessage.size());
requestBody.writeAll(encodedMessage);
Response response = client.newCall(new Request.Builder().url(url(server, "/zipkin.proto3.SpanService/Report")).addHeader("te", "trailers").post(RequestBody.create(requestBody.snapshot(), MediaType.get("application/grpc"))).build()).execute();
BufferedSource responseBody = response.body().source();
// uncompressed
assertThat((int) responseBody.readByte()).isEqualTo(0);
long encodedLength = responseBody.readInt() & 0xffffffffL;
return ReportResponse.ADAPTER.decode(responseBody);
}
use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class HttpCall method sendRequest.
CompletableFuture<AggregatedHttpResponse> sendRequest() {
final HttpResponse response;
try (SafeCloseable ignored = Clients.withContextCustomizer(ctx -> ctx.logBuilder().name(name))) {
HttpRequestWriter httpRequest = HttpRequest.streaming(request.headers());
response = httpClient.execute(httpRequest);
request.writeBody(httpRequest::tryWrite);
httpRequest.close();
}
CompletableFuture<AggregatedHttpResponse> responseFuture = RequestContext.mapCurrent(ctx -> response.aggregateWithPooledObjects(ctx.eventLoop(), ctx.alloc()), // This should never be used in practice since the module runs in an Armeria server.
response::aggregate);
responseFuture = responseFuture.exceptionally(t -> {
if (t instanceof UnprocessedRequestException) {
Throwable cause = t.getCause();
// Go ahead and reduce the output in logs since this is usually a configuration or
// infrastructure issue and the Armeria stack trace won't help debugging that.
Exceptions.clearTrace(cause);
String message = cause.getMessage();
if (message == null)
message = cause.getClass().getSimpleName();
throw new RejectedExecutionException(message, cause);
} else {
Exceptions.throwUnsafely(t);
}
return null;
});
this.responseFuture = responseFuture;
return responseFuture;
}
use of zipkin2.Span.Kind.SERVER in project zipkin by openzipkin.
the class ElasticsearchSpanConsumerTest method choosesTypeSpecificIndex.
@Test
void choosesTypeSpecificIndex() throws Exception {
server.enqueue(SUCCESS_RESPONSE);
Span span = Span.newBuilder().traceId("1").id("2").parentId("1").name("s").localEndpoint(APP_ENDPOINT).addAnnotation(TimeUnit.DAYS.toMicros(365), /* 1971-01-01 */
"foo").build();
// sanity check data
assertThat(span.timestamp()).isNull();
accept(span);
// index timestamp is the server timestamp, not current time!
assertThat(server.takeRequest().request().contentUtf8()).startsWith("{\"index\":{\"_index\":\"zipkin:span-1971-01-01\",\"_type\":\"span\"");
}
Aggregations