Search in sources :

Example 46 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class TracingProducerTest method should_add_parent_trace_when_context_injected_on_headers.

@Test
public void should_add_parent_trace_when_context_injected_on_headers() {
    ProducerRecord<Object, String> record = new ProducerRecord<>(TEST_TOPIC, TEST_KEY, TEST_VALUE);
    tracingProducer.injector.inject(parent, new KafkaProducerRequest(record));
    tracingProducer.send(record);
    mockProducer.completeNext();
    MutableSpan producerSpan = spans.get(0);
    assertThat(producerSpan.kind()).isEqualTo(PRODUCER);
    assertChildOf(producerSpan, parent);
    assertThat(lastHeaders(mockProducer)).containsEntry("b3", producerSpan.traceId() + "-" + producerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) Test(org.junit.Test)

Example 47 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class NoopAwareSpanHandlerTest method doesntCrashOnNonFatalThrowable.

@Test
public void doesntCrashOnNonFatalThrowable() {
    Throwable[] toThrow = new Throwable[1];
    SpanHandler handler = NoopAwareSpanHandler.create(new SpanHandler[] { new SpanHandler() {

        @Override
        public boolean end(TraceContext context, MutableSpan span, Cause cause) {
            doThrowUnsafely(toThrow[0]);
            return true;
        }
    } }, noop);
    toThrow[0] = new RuntimeException();
    assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
    toThrow[0] = new Exception();
    assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
    toThrow[0] = new Error();
    assertThat(handler.end(context, span, Cause.FINISHED)).isTrue();
    // fatal
    toThrow[0] = new StackOverflowError();
    try {
        // assertThatThrownBy doesn't work with StackOverflowError
        handler.end(context, span, Cause.FINISHED);
        failBecauseExceptionWasNotThrown(StackOverflowError.class);
    } catch (StackOverflowError e) {
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) Cause(brave.handler.SpanHandler.Cause) TraceContext(brave.propagation.TraceContext) SpanHandler(brave.handler.SpanHandler) Test(org.junit.Test)

Example 48 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class ZipkinJsonV2JsonWriterTest method missingFields_testCases.

@Test
public void missingFields_testCases() {
    jsonWriter.write(MutableSpanTest.PERMUTATIONS.get(0).get(), buffer);
    assertThat(buffer.toString()).isEqualTo("{}");
    // check for simple bugs
    for (int i = 1, length = MutableSpanTest.PERMUTATIONS.size(); i < length; i++) {
        buffer.pos = 0;
        MutableSpan span = MutableSpanTest.PERMUTATIONS.get(i).get();
        jsonWriter.write(span, buffer);
        assertThat(buffer.toString()).doesNotContain("null").doesNotContain(":0");
    }
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test) MutableSpanTest(brave.handler.MutableSpanTest)

Example 49 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class ZipkinJsonV2JsonWriterTest method specialCharacters.

@Test
public void specialCharacters() {
    MutableSpan span = new MutableSpan();
    span.name("\u2028 and \u2029");
    span.localServiceName("\"foo");
    span.tag("hello \n", "\t\b");
    span.annotate(1L, "\uD83D\uDCA9");
    jsonWriter.write(span, buffer);
    String string = buffer.toString();
    assertThat(string).isEqualTo("{\"name\":\"\\u2028 and \\u2029\",\"localEndpoint\":{\"serviceName\":\"\\\"foo\"},\"annotations\":[{\"timestamp\":1,\"value\":\"\uD83D\uDCA9\"}],\"tags\":{\"hello \\n\":\"\\t\\b\"}}");
    assertThat(jsonWriter.sizeInBytes(span)).isEqualTo(string.getBytes(UTF_8).length);
}
Also used : MutableSpan(brave.handler.MutableSpan) Test(org.junit.Test) MutableSpanTest(brave.handler.MutableSpanTest)

Example 50 with MutableSpan

use of brave.handler.MutableSpan in project brave by openzipkin.

the class OrphanTrackerTest method setup.

@Before
public void setup() {
    defaultSpan = new MutableSpan();
    defaultSpan.localServiceName(TracerTest.class.getSimpleName());
    defaultSpan.localIp("127.0.0.1");
    // same as how PendingSpans initializes
    span = new MutableSpan(context, defaultSpan);
    tracker = orphanTrackerWithFakeLogger();
}
Also used : MutableSpan(brave.handler.MutableSpan) TracerTest(brave.TracerTest) Before(org.junit.Before)

Aggregations

MutableSpan (brave.handler.MutableSpan)141 Test (org.junit.Test)107 TraceContext (brave.propagation.TraceContext)36 KafkaStreams (org.apache.kafka.streams.KafkaStreams)28 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)28 Topology (org.apache.kafka.streams.Topology)28 Scope (brave.propagation.CurrentTraceContext.Scope)14 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)12 KeyValue (org.apache.kafka.streams.KeyValue)9 ArrayList (java.util.ArrayList)8 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)8 MessagingTracing (brave.messaging.MessagingTracing)7 FileNotFoundException (java.io.FileNotFoundException)7 Arrays (java.util.Arrays)7 List (java.util.List)7 CONSUMER (brave.Span.Kind.CONSUMER)6 PRODUCER (brave.Span.Kind.PRODUCER)6 SpanHandler (brave.handler.SpanHandler)6 KafkaTracing (brave.kafka.clients.KafkaTracing)6 KAFKA_STREAMS_FILTERED_TAG (brave.kafka.streams.KafkaStreamsTags.KAFKA_STREAMS_FILTERED_TAG)6