Search in sources :

Example 71 with MutableSpan

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

the class IntegrationTestSpanHandler method takeRemoteSpanWithErrorMessage.

/**
 * Use instead of {@link #takeRemoteSpanWithError(Kind, Throwable)} when you cannot catch a
 * reference to the actual raised exception during a test.
 *
 * <p>This is typically used when testing framework errors result in a finished span.
 *
 * @see #takeRemoteSpanWithError(Kind, Throwable)
 * @see #takeRemoteSpanWithError(Kind)
 * @see #takeRemoteSpanWithErrorTag(Kind, String)
 */
public MutableSpan takeRemoteSpanWithErrorMessage(Kind kind, String errorMessage) {
    MutableSpan result = doTakeSpan(null, errorMessage, null, false);
    assertRemoteSpan(result, kind);
    return result;
}
Also used : MutableSpan(brave.handler.MutableSpan)

Example 72 with MutableSpan

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

the class IntegrationTestSpanHandler method assertSpansConsumed.

/**
 * On close, we check that all spans have been verified by the test. This ensures bad behavior
 * such as duplicate reporting doesn't occur. The impact is that every span must at least be
 * {@link #doTakeSpan(Throwable, String, String, boolean)} before the end of each method.
 */
// only check success path to avoid masking assertion errors or exceptions
void assertSpansConsumed() {
    if (ignoreAnySpans)
        return;
    try {
        MutableSpan span = spans.poll(100, TimeUnit.MILLISECONDS);
        assertThat(span).withFailMessage("Span remaining in queue. Check for redundant reporting: %s", span).isNull();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new AssertionError(e);
    }
}
Also used : MutableSpan(brave.handler.MutableSpan)

Example 73 with MutableSpan

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

the class IntegrationTestSpanHandler method takeRemoteSpanWithErrorTag.

/**
 * Like {@link #takeRemoteSpan(Kind)} except an error tag must match the given value.
 *
 * @see #takeRemoteSpanWithError(Kind, Throwable)
 * @see #takeRemoteSpanWithError(Kind)
 * @see #takeRemoteSpanWithErrorMessage(Kind, String)
 */
public MutableSpan takeRemoteSpanWithErrorTag(Kind kind, String errorTag) {
    MutableSpan result = doTakeSpan(null, null, errorTag, false);
    assertRemoteSpan(result, kind);
    return result;
}
Also used : MutableSpan(brave.handler.MutableSpan)

Example 74 with MutableSpan

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

the class IntegrationTestSpanHandler method takeRemoteSpan.

/**
 * Blocks until a remote span was finished. We define a remote span as one with a timestamp,
 * duration and kind.
 *
 * <p>This will fail if there's an {@link MutableSpan#error()} or an "error" tag. If you expect a
 * failure, use {@link #takeRemoteSpanWithError(Kind, Throwable)} or {@link
 * #takeRemoteSpanWithErrorTag(Kind, String)} instead.
 */
public MutableSpan takeRemoteSpan(Kind kind) {
    MutableSpan result = doTakeSpan(null, null, null, false);
    assertRemoteSpan(result, kind);
    return result;
}
Also used : MutableSpan(brave.handler.MutableSpan)

Example 75 with MutableSpan

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

the class IntegrationTestSpanHandler method takeRemoteSpanWithError.

/**
 * Some frameworks swallow exceptions. This tests that either an "error" tag exists or {@link
 * MutableSpan#error()} does, without regards to the value.
 *
 * @see #takeRemoteSpanWithError(Kind, Throwable)
 * @see #takeRemoteSpanWithErrorMessage(Kind, String)
 * @see #takeRemoteSpanWithErrorTag(Kind, String)
 */
public MutableSpan takeRemoteSpanWithError(Kind kind) {
    MutableSpan result = doTakeSpan(null, null, ANY_STRING, false);
    assertRemoteSpan(result, kind);
    return result;
}
Also used : MutableSpan(brave.handler.MutableSpan)

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