JmsTracing { public Span nextSpan(Message message) { TraceContextOrSamplingFlags extracted = extractAndClearTraceIdProperties(processorExtractor, message, message); Span result = tracer.nextSpan(extracted); if (extracted.context() == null && !result.isNoop()) { tagQueueOrTopic(new MessageConsumerRequest(message, destination(message)), result); } return result; } JmsTracing(Builder builder); static JmsTracing create(Tracing tracing); static JmsTracing create(MessagingTracing messagingTracing); static Builder newBuilder(Tracing tracing); static Builder newBuilder(MessagingTracing messagingTracing); Connection connection(Connection connection); QueueConnection queueConnection(QueueConnection connection); TopicConnection topicConnection(TopicConnection connection); XAConnection xaConnection(XAConnection xaConnection); XAQueueConnection xaQueueConnection(XAQueueConnection connection); XATopicConnection xaTopicConnection(XATopicConnection connection); ConnectionFactory connectionFactory(ConnectionFactory connectionFactory); XAConnectionFactory xaConnectionFactory(XAConnectionFactory xaConnectionFactory); MessageListener messageListener(MessageListener messageListener, boolean addConsumerSpan); Span nextSpan(Message message);  }
@Test public void nextSpan_prefers_b3_header() { TraceContext incoming = newTraceContext(SamplingFlags.NOT_SAMPLED); setStringProperty(message, "b3", B3SingleFormat.writeB3SingleFormat(incoming)); Span child; try (Scope ws = tracing.currentTraceContext().newScope(parent)) { child = jmsTracing.nextSpan(message); } assertChildOf(child.context(), incoming); assertThat(child.isNoop()).isTrue(); }
@Test public void nextSpan_uses_current_context() { Span child; try (Scope ws = tracing.currentTraceContext().newScope(parent)) { child = jmsTracing.nextSpan(message); } assertChildOf(child.context(), parent); }
@Test public void nextSpan_should_use_span_from_headers_as_parent() { setStringProperty(message, "b3", "0000000000000001-0000000000000002-1"); Span span = jmsTracing.nextSpan(message); assertThat(span.context().parentId()).isEqualTo(2L); }
@Test public void nextSpan_should_create_span_if_no_headers() { Span span = jmsTracing.nextSpan(message); assertThat(span).isNotNull(); }
@Test public void nextSpan_should_tag_queue_when_no_incoming_context() { message.setDestination(createDestination("foo", QUEUE_TYPE)); jmsTracing.nextSpan(message).start().finish(); assertThat(testSpanHandler.takeLocalSpan().tags()) .containsOnly(entry("jms.queue", "foo")); }
@Test public void nextSpan_shouldnt_tag_queue_when_incoming_context() { setStringProperty(message, "b3", "0000000000000001-0000000000000002-1"); message.setDestination(createDestination("foo", QUEUE_TYPE)); jmsTracing.nextSpan(message).start().finish(); assertThat(testSpanHandler.takeLocalSpan().tags()).isEmpty(); }
@Test public void nextSpan_should_clear_propagation_headers() { Propagation.B3_STRING.injector(SETTER).inject(parent, message); Propagation.B3_SINGLE_STRING.injector(SETTER).inject(parent, message); jmsTracing.nextSpan(message); assertThat(ITJms.propertiesToMap(message)).isEmpty(); }
@Test public void nextSpan_should_retain_baggage_headers() throws JMSException { message.setStringProperty(BAGGAGE_FIELD_KEY, ""); jmsTracing.nextSpan(message); assertThat(message.getStringProperty(BAGGAGE_FIELD_KEY)).isEmpty(); }
@Test public void nextSpan_should_not_clear_other_headers() throws JMSException { message.setIntProperty("foo", 1); jmsTracing.nextSpan(message); assertThat(message.getIntProperty("foo")).isEqualTo(1); }