Search in sources :

Example 71 with Span

use of zipkin2.proto3.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);
}
Also used : Endpoint(zipkin2.Endpoint) Span(zipkin2.Span) Test(org.junit.Test)

Example 72 with Span

use of zipkin2.proto3.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"));
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Example 73 with Span

use of zipkin2.proto3.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);
        }
    }
}
Also used : Span(zipkin2.Span)

Example 74 with Span

use of zipkin2.proto3.Span in project zipkin by openzipkin.

the class ITEnsureIndexTemplate method createZipkinIndexTemplate_getTraces_returnsSuccess.

@Test
void createZipkinIndexTemplate_getTraces_returnsSuccess(TestInfo testInfo) throws Exception {
    String testSuffix = testSuffix(testInfo);
    storage = newStorageBuilder(testInfo).templatePriority(10).build();
    try {
        // Delete all templates in order to create the "catch-all" index template, because
        // ES does not allow multiple index templates of the same index_patterns and priority
        http(DELETE, "/_template/*");
        setUpCatchAllTemplate();
        // Implicitly creates an index template
        checkStorage();
        // Get all templates. We don't assert on this at the moment. This is for logging on ES_DEBUG.
        http(GET, "/_template");
        // Now, add a span, which should be indexed differently than default.
        Span span = spanBuilder(testSuffix).putTag("queryTest", "ok").build();
        accept(asList(span));
        // Assert that Zipkin's templates work and source is returned
        assertGetTracesReturns(requestBuilder().parseAnnotationQuery("queryTest=" + span.tags().get("queryTest")).build(), asList(span));
    } finally {
        // Delete "catch-all" index template so it does not interfere with any other test
        http(DELETE, catchAllIndexPath());
    }
}
Also used : Span(zipkin2.Span) Test(org.junit.jupiter.api.Test)

Example 75 with Span

use of zipkin2.proto3.Span in project zipkin by openzipkin.

the class BulkIndexWriterTest method spanSearchFields_addsTimestampFieldWhenNoTags.

@Test
public void spanSearchFields_addsTimestampFieldWhenNoTags() {
    Span span = Span.newBuilder().traceId("20").id("22").name("").parentId("21").timestamp(1000L).localEndpoint(FRONTEND).kind(Kind.CLIENT).build();
    BulkIndexWriter.SPAN.writeDocument(span, buffer);
    assertThat(buffer.buffer().toString(StandardCharsets.UTF_8)).startsWith("{\"timestamp_millis\":1,\"traceId\":");
}
Also used : Span(zipkin2.Span) Test(org.junit.Test)

Aggregations

Span (zipkin2.Span)290 Test (org.junit.Test)203 Test (org.junit.jupiter.api.Test)69 Endpoint (zipkin2.Endpoint)62 TestObjects.newClientSpan (zipkin2.TestObjects.newClientSpan)41 ArrayList (java.util.ArrayList)29 V1Span (zipkin2.v1.V1Span)23 List (java.util.List)19 Map (java.util.Map)18 Annotation (zipkin2.Annotation)13 AggregateCall (zipkin2.internal.AggregateCall)13 TraceSpan (com.google.devtools.cloudtrace.v1.TraceSpan)12 IOException (java.io.IOException)10 LinkedHashMap (java.util.LinkedHashMap)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 Arrays.asList (java.util.Arrays.asList)9 Span (com.google.devtools.cloudtrace.v2.Span)8 Trace (com.google.devtools.cloudtrace.v1.Trace)7 Call (zipkin2.Call)7 Span (zipkin2.proto3.Span)7