use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class ElasticsearchSpanConsumerTest method addsAutocompleteValue_revertsSuppressionOnFailure.
@Test
void addsAutocompleteValue_revertsSuppressionOnFailure() throws Exception {
server.enqueue(AggregatedHttpResponse.of(HttpStatus.INTERNAL_SERVER_ERROR));
server.enqueue(SUCCESS_RESPONSE);
Span s = Span.newBuilder().traceId("1").id("1").timestamp(1).putTag("environment", "A").build();
try {
accept(s);
failBecauseExceptionWasNotThrown(RuntimeException.class);
} catch (RuntimeException expected) {
}
accept(s);
// We only cache when there was no error.. the second request should be same as the first
assertThat(server.takeRequest().request().contentUtf8()).isEqualTo(server.takeRequest().request().contentUtf8());
}
use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class ElasticsearchSpanConsumerTest method writesSpanNaturallyWhenNoTimestamp.
@Test
void writesSpanNaturallyWhenNoTimestamp() throws Exception {
server.enqueue(SUCCESS_RESPONSE);
Span span = Span.newBuilder().traceId("1").id("1").name("foo").build();
accept(Span.newBuilder().traceId("1").id("1").name("foo").build());
assertThat(server.takeRequest().request().contentUtf8()).contains("\n" + new String(SpanBytesEncoder.JSON_V2.encode(span), UTF_8) + "\n");
}
use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class JsonSerializersTest method span_specialCharsInJson.
/**
* This isn't a test of what we "should" accept as a span, rather that characters that trip-up
* json don't fail in SPAN_PARSER.
*/
@Test
public void span_specialCharsInJson() {
// service name is surrounded by control characters
Endpoint e = Endpoint.newBuilder().serviceName(new String(new char[] { 0, 'a', 1 })).build();
Span worstSpanInTheWorld = Span.newBuilder().traceId("1").id("1").name(new String(new char[] { '"', '\\', '\t', '\b', '\n', '\r', '\f' })).localEndpoint(e).addAnnotation(1L, "\u2028 and \u2029").putTag("\"foo", "Database error: ORA-00942:\u2028 and \u2029 table or view does not exist\n").build();
assertThat(parse(SPAN_PARSER, new String(SpanBytesEncoder.JSON_V2.encode(worstSpanInTheWorld), UTF_8))).isEqualTo(worstSpanInTheWorld);
}
use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class JsonSerializersTest method span_tag_double_read.
@Test
public void span_tag_double_read() {
String json = "{\n" + " \"traceId\": \"6b221d5bc9e6496c\",\n" + " \"name\": \"get-traces\",\n" + " \"id\": \"6b221d5bc9e6496c\",\n" + " \"tags\": {" + " \"num\": 1.23456789" + " }" + "}";
Span span = parse(SPAN_PARSER, json);
assertThat(span.tags()).containsExactly(entry("num", "1.23456789"));
}
use of io.opentelemetry.proto.trace.v1.Span in project zipkin by openzipkin.
the class ElasticsearchSpanConsumer method indexSpans.
void indexSpans(BulkSpanIndexer indexer, List<Span> spans) {
for (Span span : spans) {
// which index to store this span into
final long indexTimestamp;
if (span.timestampAsLong() != 0L) {
indexTimestamp = span.timestampAsLong() / 1000L;
} else if (!span.annotations().isEmpty()) {
// guessTimestamp is made for determining the span's authoritative timestamp. When choosing
// the index bucket, any annotation is better than using current time.
indexTimestamp = span.annotations().get(0).timestamp() / 1000L;
} else {
indexTimestamp = System.currentTimeMillis();
}
indexer.add(indexTimestamp, span);
if (searchEnabled && !span.tags().isEmpty()) {
indexer.addAutocompleteValues(indexTimestamp, span);
}
}
}
Aggregations