use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class TracingRabbitListenerAdviceTest method batch_continue_parent_trace.
@Test
public void batch_continue_parent_trace() throws Throwable {
MessageProperties props = new MessageProperties();
props.setHeader("X-B3-TraceId", TRACE_ID);
props.setHeader("X-B3-SpanId", SPAN_ID);
props.setHeader("X-B3-ParentSpanId", PARENT_ID);
props.setHeader("X-B3-Sampled", SAMPLED);
Message message = MessageBuilder.withBody(new byte[0]).andProperties(props).build();
MessageProperties props2 = new MessageProperties();
props2.setHeader("X-B3-TraceId", TRACE_ID_2);
props2.setHeader("X-B3-SpanId", SPAN_ID_2);
props2.setHeader("X-B3-ParentSpanId", PARENT_ID_2);
props2.setHeader("X-B3-Sampled", SAMPLED);
Message message2 = MessageBuilder.withBody(new byte[0]).andProperties(props2).build();
onBatchMessageConsumed(Arrays.asList(message, message2));
// cleared the headers to later work doesn't try to use the old parent
assertThat(message.getMessageProperties().getHeaders()).isEmpty();
// two traced that listener continues first trace but TODO we aren't handling the second.
assertThat(spans.get(0)).extracting(MutableSpan::parentId).isEqualTo(SPAN_ID);
}
use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class TracingRabbitListenerAdvice method invoke.
/**
* MethodInterceptor for {@link SimpleMessageListenerContainer.ContainerDelegate#invokeListener(Channel,
* Message)}
*/
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Message message = null;
if (methodInvocation.getArguments()[1] instanceof List) {
message = ((List<? extends Message>) methodInvocation.getArguments()[1]).get(0);
} else {
message = (Message) methodInvocation.getArguments()[1];
}
MessageConsumerRequest request = new MessageConsumerRequest(message);
TraceContextOrSamplingFlags extracted = springRabbitTracing.extractAndClearTraceIdHeaders(extractor, request, message);
// named for BlockingQueueConsumer.nextMessage, which we can't currently see
Span consumerSpan = springRabbitTracing.nextMessagingSpan(sampler, request, extracted);
Span listenerSpan = tracer.newChild(consumerSpan.context());
if (!consumerSpan.isNoop()) {
setConsumerSpan(consumerSpan, message.getMessageProperties());
// incur timestamp overhead only once
long timestamp = tracing.clock(consumerSpan.context()).currentTimeMicroseconds();
consumerSpan.start(timestamp);
// save a clock reading
long consumerFinish = timestamp + 1L;
consumerSpan.finish(consumerFinish);
// not using scoped span as we want to start with a pre-configured time
listenerSpan.name("on-message").start(consumerFinish);
}
Tracer.SpanInScope ws = tracer.withSpanInScope(listenerSpan);
Throwable error = null;
try {
return methodInvocation.proceed();
} catch (Throwable t) {
error = t;
throw t;
} finally {
if (error != null)
listenerSpan.error(error);
listenerSpan.finish();
ws.close();
}
}
use of org.springframework.amqp.core.Message in project brave by openzipkin.
the class ITSpringRabbitTracing method clears_message_headers_after_propagation.
@Test
public void clears_message_headers_after_propagation() {
produceMessage();
awaitMessageConsumed();
Message capturedMessage = awaitMessageConsumed();
Map<String, Object> headers = capturedMessage.getMessageProperties().getHeaders();
assertThat(headers.keySet()).containsExactly("not-zipkin-header");
producerSpanHandler.takeRemoteSpan(PRODUCER);
consumerSpanHandler.takeRemoteSpan(CONSUMER);
consumerSpanHandler.takeLocalSpan();
}
Aggregations