Search in sources :

Example 61 with MutableSpan

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

the class ITTracingJMSConsumer method receiveResumesTrace.

void receiveResumesTrace(Runnable send) {
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    producer.setProperty("b3", parent.traceIdString() + "-" + parent.spanIdString() + "-1");
    send.run();
    Message received = consumer.receive();
    MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertChildOf(consumerSpan, parent);
    assertThat(getPropertyIfString(received, "b3")).isEqualTo(parent.traceIdString() + "-" + consumerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) Message(javax.jms.Message) TraceContext(brave.propagation.TraceContext)

Example 62 with MutableSpan

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

the class ITTracingJMSConsumer method messageListener_resumesTrace.

void messageListener_resumesTrace(Runnable send) {
    consumer.setMessageListener(m -> {
        // clearing headers ensures later work doesn't try to use the old parent
        String b3 = getPropertyIfString(m, "b3");
        tracing.tracer().currentSpanCustomizer().tag("b3", String.valueOf(b3 != null));
    });
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    producer.setProperty("b3", parent.traceIdString() + "-" + parent.spanIdString() + "-1");
    send.run();
    MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
    MutableSpan listenerSpan = testSpanHandler.takeLocalSpan();
    assertChildOf(consumerSpan, parent);
    assertChildOf(listenerSpan, consumerSpan);
    assertThat(listenerSpan.tags()).hasSize(// no redundant copy of consumer tags
    1).containsEntry("b3", // b3 header not leaked to listener
    "false");
}
Also used : MutableSpan(brave.handler.MutableSpan) TraceContext(brave.propagation.TraceContext) MessageProperties.getPropertyIfString(brave.jms.MessageProperties.getPropertyIfString)

Example 63 with MutableSpan

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

the class TracingJMSConsumerTest method receive_continues_parent_trace_single_header.

@Test
public void receive_continues_parent_trace_single_header() throws Exception {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    message.setStringProperty("b3", B3SingleFormat.writeB3SingleFormatWithoutParentId(parent));
    receive(message);
    // Ensure the current span in on the message, not the parent
    MutableSpan consumer = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertChildOf(consumer, parent);
    TraceContext messageContext = parseB3SingleFormat(message.getStringProperty("b3")).context();
    assertThat(messageContext.traceIdString()).isEqualTo(consumer.traceId());
    assertThat(messageContext.spanIdString()).isEqualTo(consumer.id());
}
Also used : MutableSpan(brave.handler.MutableSpan) TraceContext(brave.propagation.TraceContext) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 64 with MutableSpan

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

the class TracingMessageListenerTest method continues_parent_trace_single_header.

@Test
public void continues_parent_trace_single_header() {
    ActiveMQTextMessage message = new ActiveMQTextMessage();
    setStringProperty(message, "b3", B3SingleFormat.writeB3SingleFormatWithoutParentId(parent));
    onMessageConsumed(message);
    // clearing headers ensures later work doesn't try to use the old parent
    assertNoProperties(message);
    MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
    MutableSpan listenerSpan = testSpanHandler.takeLocalSpan();
    assertChildOf(consumerSpan, parent);
    assertChildOf(listenerSpan, consumerSpan);
}
Also used : MutableSpan(brave.handler.MutableSpan) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 65 with MutableSpan

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

the class IntegrationTestSpanHandler method takeLocalSpan.

/**
 * Blocks until a local span was finished. This does <em>not</em> verify errors.
 */
public MutableSpan takeLocalSpan() {
    MutableSpan result = doTakeSpan(false);
    assertThat(result.kind()).withFailMessage("Expected %s to have no kind", result).isNull();
    assertThat(result.remoteServiceName()).withFailMessage("Expected %s to have no remote endpoint", result).isNull();
    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