Search in sources :

Example 51 with MutableSpan

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

the class ITJms_1_1_TracingMessageProducer method should_prefer_current_to_stale_b3_header.

@Test
public void should_prefer_current_to_stale_b3_header() throws JMSException {
    jms.setReadOnlyProperties(message, false);
    setStringProperty(message, "b3", writeB3SingleFormat(newTraceContext(SamplingFlags.NOT_SAMPLED)));
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    try (Scope scope = currentTraceContext.newScope(parent)) {
        messageProducer.send(jms.destination, message);
    }
    Message received = messageConsumer.receive();
    MutableSpan producerSpan = testSpanHandler.takeRemoteSpan(PRODUCER);
    assertChildOf(producerSpan, parent);
    assertThat(propertiesToMap(received)).containsAllEntriesOf(existingProperties).containsEntry("b3", producerSpan.traceId() + "-" + producerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 52 with MutableSpan

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

the class ITJms_1_1_TracingMessageProducer method should_record_properties.

void should_record_properties(Map<String, String> producerTags) {
    MutableSpan producerSpan = testSpanHandler.takeRemoteSpan(PRODUCER);
    assertThat(producerSpan.name()).isEqualTo("send");
    assertThat(producerSpan.tags()).containsAllEntriesOf(producerTags);
}
Also used : MutableSpan(brave.handler.MutableSpan)

Example 53 with MutableSpan

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

the class ITTracingJMSProducer method should_not_serialize_parent_span_id.

@Test
public void should_not_serialize_parent_span_id() {
    TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
    try (Scope scope = currentTraceContext.newScope(parent)) {
        producer.send(jms.queue, "foo");
    }
    Message received = consumer.receive();
    MutableSpan producerSpan = testSpanHandler.takeRemoteSpan(PRODUCER);
    assertChildOf(producerSpan, parent);
    assertThat(propertiesToMap(received)).containsAllEntriesOf(existingProperties).containsEntry("b3", producerSpan.traceId() + "-" + producerSpan.id() + "-1");
}
Also used : MutableSpan(brave.handler.MutableSpan) Scope(brave.propagation.CurrentTraceContext.Scope) Message(javax.jms.Message) TraceContext(brave.propagation.TraceContext) Test(org.junit.Test)

Example 54 with MutableSpan

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

the class ITJms_1_1_TracingMessageConsumer method messageListener_startsNewTrace.

void messageListener_startsNewTrace(JMSRunnable send, MessageConsumer messageConsumer, Map<String, String> consumerTags) throws JMSException {
    messageConsumer.setMessageListener(m -> {
        tracing.tracer().currentSpanCustomizer().name("message-listener");
        // 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));
    });
    send.run();
    MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
    MutableSpan listenerSpan = testSpanHandler.takeLocalSpan();
    assertThat(consumerSpan.name()).isEqualTo("receive");
    // root span
    assertThat(consumerSpan.parentId()).isNull();
    assertThat(consumerSpan.tags()).containsAllEntriesOf(consumerTags);
    assertChildOf(listenerSpan, consumerSpan);
    // overridden name
    assertThat(listenerSpan.name()).isEqualTo("message-listener");
    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) MessageProperties.getPropertyIfString(brave.jms.MessageProperties.getPropertyIfString)

Example 55 with MutableSpan

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

the class ITJms_1_1_TracingMessageConsumer method receive_startsNewTrace.

void receive_startsNewTrace(JMSRunnable send, MessageConsumer messageConsumer, Map<String, String> consumerTags) throws JMSException {
    send.run();
    messageConsumer.receive();
    MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertThat(consumerSpan.name()).isEqualTo("receive");
    // root span
    assertThat(consumerSpan.parentId()).isNull();
    assertThat(consumerSpan.tags()).containsAllEntriesOf(consumerTags);
}
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