@Test public void testReceiveWithoutTracingContext() { MockTracer mockTracer = new MockTracer(); JmsTracer jmsTracer = new OpenTracingTracer(mockTracer, true); String consumerDestination = "myAddress"; TraceableMessage message = Mockito.mock(TraceableMessage.class); Mockito.when(message.getTracingAnnotation(ANNOTATION_KEY)).thenReturn(null); assertTrue("Expected no finished spans", mockTracer.finishedSpans().isEmpty()); jmsTracer.syncReceive(message, consumerDestination, DeliveryOutcome.DELIVERED); ArgumentCaptor<Span> deliverySpanCapture = ArgumentCaptor.forClass(Span.class); Mockito.verify(message).getTracingAnnotation(Mockito.eq(ANNOTATION_KEY)); Mockito.verify(message).setTracingContext(Mockito.eq(DELIVERY_SPAN_CONTEXT_KEY), deliverySpanCapture.capture()); Mockito.verifyNoMoreInteractions(message); Span deliverySpan = deliverySpanCapture.getValue(); assertNotNull("expected a span from receive operation", deliverySpan); assertEquals("Unexpected span class", MockSpan.class, deliverySpan.getClass()); MockSpan deliveryMockSpan = (MockSpan) deliverySpan; assertEquals("Unexpected span operation name", RECEIVE_SPAN_NAME, deliveryMockSpan.operationName()); List<MockSpan> finishedSpans = mockTracer.finishedSpans(); assertEquals("Expected 1 finished span: " + finishedSpans, 1, finishedSpans.size()); assertEquals("Unexpected finished span", deliverySpan, finishedSpans.get(0)); assertEquals("Expected span to have no parent span", 0, deliveryMockSpan.parentId()); Map<String, Object> spanTags = deliveryMockSpan.tags(); assertFalse("Expected some tags", spanTags.isEmpty()); assertEquals(Tags.SPAN_KIND_CONSUMER, spanTags.get(Tags.SPAN_KIND.getKey())); assertEquals(consumerDestination, spanTags.get(Tags.MESSAGE_BUS_DESTINATION.getKey())); assertEquals(COMPONENT, spanTags.get(Tags.COMPONENT.getKey())); }
@Override public void syncReceive(TraceableMessage message, String address, DeliveryOutcome outcome) { SpanContext context = extract(message); Span span = tracer.buildSpan(RECEIVE_SPAN_NAME) .asChildOf(context) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER) .withTag(Tags.MESSAGE_BUS_DESTINATION, address) .withTag(Tags.COMPONENT, COMPONENT) .start(); try { addDeliveryLogIfNeeded(outcome, span); } finally { span.finish(); } message.setTracingContext(DELIVERY_SPAN_CONTEXT_KEY, span); }
OpenTracingTracer implements JmsTracer { @Override public void syncReceive(TraceableMessage message, String address, DeliveryOutcome outcome) { SpanContext context = extract(message); Span span = tracer.buildSpan(RECEIVE_SPAN_NAME) .asChildOf(context) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER) .withTag(Tags.MESSAGE_BUS_DESTINATION, address) .withTag(Tags.COMPONENT, COMPONENT) .start(); try { addDeliveryLogIfNeeded(outcome, span); } finally { span.finish(); } message.setTracingContext(DELIVERY_SPAN_CONTEXT_KEY, span); } }
OpenTracingTracer implements JmsTracer { @Override public void syncReceive(TraceableMessage message, String address, DeliveryOutcome outcome) { SpanContext context = extract(message); Span span = tracer.buildSpan(RECEIVE_SPAN_NAME) .asChildOf(context) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER) .withTag(Tags.MESSAGE_BUS_DESTINATION, address) .withTag(Tags.COMPONENT, COMPONENT) .start(); try { addDeliveryLogIfNeeded(outcome, span); } finally { span.finish(); } message.setTracingContext(DELIVERY_SPAN_CONTEXT_KEY, span); } OpenTracingTracer(Tracer tracer, boolean closeUnderlyingTracer); }
OpenTracingTracer implements JmsTracer { @Override public void syncReceive(TraceableMessage message, String address, DeliveryOutcome outcome) { SpanContext context = extract(message); Span span = tracer.buildSpan(RECEIVE_SPAN_NAME) .asChildOf(context) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER) .withTag(Tags.MESSAGE_BUS_DESTINATION, address) .withTag(Tags.COMPONENT, COMPONENT) .start(); try { addDeliveryLogIfNeeded(outcome, span); } finally { span.finish(); } message.setTracingContext(DELIVERY_SPAN_CONTEXT_KEY, span); } OpenTracingTracer(Tracer tracer, boolean closeUnderlyingTracer); @Override void initSend(TraceableMessage message, String address); @Override void completeSend(TraceableMessage message, String outcome); @Override void syncReceive(TraceableMessage message, String address, DeliveryOutcome outcome); @Override void asyncDeliveryInit(TraceableMessage message, String address); @Override void asyncDeliveryComplete(TraceableMessage message, DeliveryOutcome outcome, Throwable throwable); @Override void close(); }
OpenTracingTracer implements JmsTracer { @Override public void syncReceive(TraceableMessage message, String address, DeliveryOutcome outcome) { SpanContext context = extract(message); Span span = tracer.buildSpan(RECEIVE_SPAN_NAME) .asChildOf(context) .withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_CONSUMER) .withTag(Tags.MESSAGE_BUS_DESTINATION, address) .withTag(Tags.COMPONENT, COMPONENT) .start(); try { addDeliveryLogIfNeeded(outcome, span); } finally { span.finish(); } message.setTracingContext(DELIVERY_SPAN_CONTEXT_KEY, span); } OpenTracingTracer(Tracer tracer, boolean closeUnderlyingTracer); @Override void initSend(TraceableMessage message, String address); @Override void completeSend(TraceableMessage message, String outcome); @Override void syncReceive(TraceableMessage message, String address, DeliveryOutcome outcome); @Override void asyncDeliveryInit(TraceableMessage message, String address); @Override void asyncDeliveryComplete(TraceableMessage message, DeliveryOutcome outcome, Throwable throwable); @Override void close();  }