Search in sources :

Example 1 with MessagingTracing

use of brave.messaging.MessagingTracing in project brave by openzipkin.

the class ITJms_1_1_TracingMessageProducer method customSampler.

@Test
public void customSampler() throws JMSException {
    queueSender.close();
    tracedQueueSession.close();
    MessagingRuleSampler producerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
    try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).producerSampler(producerSampler).build()) {
        // JMS 1.1 didn't have auto-closeable. tearDownTraced closes these
        tracedQueueSession = JmsTracing.create(messagingTracing).queueConnection(jms.queueConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        queueSender = tracedQueueSession.createSender(jms.queue);
        queueSender.send(message);
    }
    Message received = queueReceiver.receive();
    assertThat(propertiesToMap(received)).containsKey("b3").satisfies(m -> assertThat(m.get("b3")).endsWith("-0"));
// @After will also check that the producer was not sampled
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) Test(org.junit.Test)

Example 2 with MessagingTracing

use of brave.messaging.MessagingTracing in project brave by openzipkin.

the class ITJms_2_0_TracingMessageProducer method customSampler.

@Test
public void customSampler() throws JMSException {
    MessagingRuleSampler producerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
    try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).producerSampler(producerSampler).build();
        JMSContext context = JmsTracing.create(messagingTracing).connectionFactory(((ArtemisJmsTestRule) jms).factory).createContext(JMSContext.AUTO_ACKNOWLEDGE)) {
        context.createProducer().send(jms.queue, "foo");
    }
    Message received = queueReceiver.receive();
    assertThat(propertiesToMap(received)).containsKey("b3").satisfies(m -> assertThat(m.get("b3")).endsWith("-0"));
// @After will also check that the producer was not sampled
}
Also used : Message(javax.jms.Message) MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 3 with MessagingTracing

use of brave.messaging.MessagingTracing in project brave by openzipkin.

the class ITJms_1_1_TracingMessageConsumer method receive_customSampler.

@Test
public void receive_customSampler() throws JMSException {
    queueReceiver.close();
    tracedSession.close();
    MessagingRuleSampler consumerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
    try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).consumerSampler(consumerSampler).build()) {
        // JMS 1.1 didn't have auto-closeable. tearDownTraced closes these
        tracedQueueSession = JmsTracing.create(messagingTracing).queueConnection(jms.queueConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        messageConsumer = tracedQueueSession.createConsumer(jms.queue);
        queueSender.send(message);
        // Check that the message headers are not sampled
        assertThat(messageConsumer.receive().getStringProperty("b3")).endsWith("-0");
    }
// @After will also check that the consumer was not sampled
}
Also used : MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) Test(org.junit.Test)

Example 4 with MessagingTracing

use of brave.messaging.MessagingTracing in project brave by openzipkin.

the class ITJms_2_0_TracingMessageConsumer method receive_customSampler.

@Test
public void receive_customSampler() throws JMSException {
    queueReceiver.close();
    MessagingRuleSampler consumerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
    try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).consumerSampler(consumerSampler).build();
        JMSContext context = JmsTracing.create(messagingTracing).connectionFactory(((ArtemisJmsTestRule) jms).factory).createContext(JMSContext.AUTO_ACKNOWLEDGE);
        JMSConsumer consumer = context.createConsumer(jms.queue)) {
        queueSender.send(message);
        // Check that the message headers are not sampled
        assertThat(consumer.receive().getStringProperty("b3")).endsWith("-0");
    }
// @After will also check that the consumer was not sampled
}
Also used : JMSConsumer(javax.jms.JMSConsumer) MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 5 with MessagingTracing

use of brave.messaging.MessagingTracing in project brave by openzipkin.

the class ITKafkaStreamsTracing method should_create_one_span_from_stream_input_topic_whenSharingEnabled.

@Test
public void should_create_one_span_from_stream_input_topic_whenSharingEnabled() {
    String inputTopic = testName.getMethodName() + "-input";
    StreamsBuilder builder = new StreamsBuilder();
    builder.stream(inputTopic).foreach((k, v) -> {
    });
    Topology topology = builder.build();
    MessagingTracing messagingTracing = MessagingTracing.create(tracing);
    KafkaStreamsTracing kafkaStreamsTracing = KafkaStreamsTracing.newBuilder(messagingTracing).singleRootSpanOnReceiveBatch(true).build();
    KafkaStreams streams = kafkaStreamsTracing.kafkaStreams(topology, streamsProperties());
    send(new ProducerRecord<>(inputTopic, TEST_KEY, TEST_VALUE));
    send(new ProducerRecord<>(inputTopic, TEST_KEY, TEST_VALUE));
    send(new ProducerRecord<>(inputTopic, TEST_KEY, TEST_VALUE));
    waitForStreamToRun(streams);
    MutableSpan spanInput = testSpanHandler.takeRemoteSpan(CONSUMER);
    assertThat(spanInput.tags()).containsEntry("kafka.topic", inputTopic);
    streams.close();
    streams.cleanUp();
}
Also used : StreamsBuilder(org.apache.kafka.streams.StreamsBuilder) KafkaStreams(org.apache.kafka.streams.KafkaStreams) MutableSpan(brave.handler.MutableSpan) MessagingTracing(brave.messaging.MessagingTracing) Topology(org.apache.kafka.streams.Topology) Test(org.junit.Test)

Aggregations

MessagingTracing (brave.messaging.MessagingTracing)5 Test (org.junit.Test)5 MessagingRuleSampler (brave.messaging.MessagingRuleSampler)4 JMSContext (javax.jms.JMSContext)2 Message (javax.jms.Message)2 MutableSpan (brave.handler.MutableSpan)1 BytesMessage (javax.jms.BytesMessage)1 JMSConsumer (javax.jms.JMSConsumer)1 TextMessage (javax.jms.TextMessage)1 KafkaStreams (org.apache.kafka.streams.KafkaStreams)1 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)1 Topology (org.apache.kafka.streams.Topology)1