use of brave.propagation.TraceContext in project brave by openzipkin.
the class ITTracingJMSConsumer method receiveResumesTrace.
void receiveResumesTrace(Runnable send) {
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
producer.setProperty("b3", parent.traceIdString() + "-" + parent.spanIdString() + "-1");
send.run();
Message received = consumer.receive();
MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
assertChildOf(consumerSpan, parent);
assertThat(getPropertyIfString(received, "b3")).isEqualTo(parent.traceIdString() + "-" + consumerSpan.id() + "-1");
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class ITTracingJMSConsumer method messageListener_resumesTrace.
void messageListener_resumesTrace(Runnable send) {
consumer.setMessageListener(m -> {
// 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));
});
TraceContext parent = newTraceContext(SamplingFlags.SAMPLED);
producer.setProperty("b3", parent.traceIdString() + "-" + parent.spanIdString() + "-1");
send.run();
MutableSpan consumerSpan = testSpanHandler.takeRemoteSpan(CONSUMER);
MutableSpan listenerSpan = testSpanHandler.takeLocalSpan();
assertChildOf(consumerSpan, parent);
assertChildOf(listenerSpan, consumerSpan);
assertThat(listenerSpan.tags()).hasSize(// no redundant copy of consumer tags
1).containsEntry("b3", // b3 header not leaked to listener
"false");
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class TracingJMSConsumerTest method receive_continues_parent_trace_single_header.
@Test
public void receive_continues_parent_trace_single_header() throws Exception {
ActiveMQTextMessage message = new ActiveMQTextMessage();
message.setStringProperty("b3", B3SingleFormat.writeB3SingleFormatWithoutParentId(parent));
receive(message);
// Ensure the current span in on the message, not the parent
MutableSpan consumer = testSpanHandler.takeRemoteSpan(CONSUMER);
assertChildOf(consumer, parent);
TraceContext messageContext = parseB3SingleFormat(message.getStringProperty("b3")).context();
assertThat(messageContext.traceIdString()).isEqualTo(consumer.traceId());
assertThat(messageContext.spanIdString()).isEqualTo(consumer.id());
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class CurrentTraceContextTest method noticesDifferentSpanId.
void noticesDifferentSpanId(Scope scope) {
TraceContext differentSpanId = context.toBuilder().spanId(context.spanId() + 1L).build();
try (Scope scope2 = currentTraceContext.maybeScope(differentSpanId)) {
assertThat(scope2).isNotEqualTo(Scope.NOOP);
assertThat(currentTraceContext.get()).isEqualTo(differentSpanId);
verifyImplicitContext(differentSpanId);
} finally {
scope.close();
}
}
use of brave.propagation.TraceContext in project brave by openzipkin.
the class TracingMessagePostProcessor method postProcessMessage.
@Override
public Message postProcessMessage(Message message) {
MessageProducerRequest request = new MessageProducerRequest(message);
TraceContext maybeParent = currentTraceContext.get();
// Unlike message consumers, we try current span before trying extraction. This is the proper
// order because the span in scope should take precedence over a potentially stale header entry.
//
// NOTE: Brave instrumentation used properly does not result in stale header entries, as we
// always clear message headers after reading.
Span span;
if (maybeParent == null) {
TraceContextOrSamplingFlags extracted = springRabbitTracing.extractAndClearTraceIdHeaders(extractor, request, message);
span = springRabbitTracing.nextMessagingSpan(sampler, request, extracted);
} else {
// If we have a span in scope assume headers were cleared before
span = tracer.newChild(maybeParent);
}
if (!span.isNoop()) {
span.kind(PRODUCER).name("publish");
if (remoteServiceName != null)
span.remoteServiceName(remoteServiceName);
// incur timestamp overhead only once
long timestamp = tracing.clock(span.context()).currentTimeMicroseconds();
span.start(timestamp).finish(timestamp);
}
injector.inject(span.context(), request);
return message;
}
Aggregations