use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracerTest method nextSpan_ensuresSampling_whenCreatingNewChild.
@Test
public void nextSpan_ensuresSampling_whenCreatingNewChild() {
TraceContext notYetSampled = tracer.newTrace().context().toBuilder().sampled(null).build();
TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(notYetSampled);
assertThat(tracer.nextSpan(extracted).context().sampled()).isTrue();
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracerTest method nextSpan_extractedTraceContext.
@Test
public void nextSpan_extractedTraceContext() {
TraceContext traceContext = TraceContext.newBuilder().traceId(1L).spanId(2L).build();
TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(traceContext);
assertThat(tracer.nextSpan(extracted).context()).extracting(TraceContext::traceId, TraceContext::parentId).containsExactly(1L, 2L);
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracerTest method nextSpan_extractedExtra_newTrace.
@Test
public void nextSpan_extractedExtra_newTrace() {
TraceContextOrSamplingFlags extracted = TraceContextOrSamplingFlags.create(SamplingFlags.EMPTY).toBuilder().addExtra(1L).build();
assertThat(tracer.nextSpan(extracted).context().extra()).containsExactly(1L);
}
use of brave.propagation.TraceContextOrSamplingFlags in project spring-cloud-sleuth by spring-cloud.
the class TracingChannelInterceptor method beforeHandle.
/**
* This starts a consumer span as a child of the incoming message or the current trace context.
* It then creates a span for the handler, placing it in scope.
*/
@Override
public Message<?> beforeHandle(Message<?> message, MessageChannel channel, MessageHandler handler) {
if (emptyMessage(message)) {
return message;
}
MessageHeaderAccessor headers = mutableHeaderAccessor(message);
TraceContextOrSamplingFlags extracted = this.extractor.extract(headers);
// Start and finish a consumer span as we will immediately process it.
Span consumerSpan = this.tracer.nextSpan(extracted);
if (!consumerSpan.isNoop()) {
consumerSpan.kind(Span.Kind.CONSUMER).start();
consumerSpan.remoteEndpoint(Endpoint.newBuilder().serviceName(REMOTE_SERVICE_NAME).build());
addTags(message, consumerSpan, channel);
consumerSpan.finish();
}
// create and scope a span for the message processor
this.threadLocalSpan.next(TraceContextOrSamplingFlags.create(consumerSpan.context())).name("handle").start();
// remove any trace headers, but don't re-inject as we are synchronously processing the
// message and can rely on scoping to access this span later.
MessageHeaderPropagation.removeAnyTraceHeaders(headers, this.tracing.propagation().keys());
if (log.isDebugEnabled()) {
log.debug("Created a new span in before handle" + consumerSpan);
}
if (message instanceof ErrorMessage) {
return new ErrorMessage((Throwable) message.getPayload(), headers.getMessageHeaders());
}
headers.setImmutable();
return new GenericMessage<>(message.getPayload(), headers.getMessageHeaders());
}
use of brave.propagation.TraceContextOrSamplingFlags in project spring-cloud-sleuth by spring-cloud.
the class TracingChannelInterceptor method postReceive.
/**
* This starts a consumer span as a child of the incoming message or the current trace context,
* placing it in scope until the receive completes.
*/
@Override
public Message<?> postReceive(Message<?> message, MessageChannel channel) {
if (emptyMessage(message)) {
return message;
}
MessageHeaderAccessor headers = mutableHeaderAccessor(message);
TraceContextOrSamplingFlags extracted = this.extractor.extract(headers);
Span span = this.threadLocalSpan.next(extracted);
MessageHeaderPropagation.removeAnyTraceHeaders(headers, this.tracing.propagation().keys());
this.injector.inject(span.context(), headers);
if (!span.isNoop()) {
span.kind(Span.Kind.CONSUMER).name("receive").start();
span.remoteEndpoint(Endpoint.newBuilder().serviceName(REMOTE_SERVICE_NAME).build());
addTags(message, span, channel);
}
if (log.isDebugEnabled()) {
log.debug("Created a new span in post receive " + span);
}
headers.setImmutable();
return new GenericMessage<>(message.getPayload(), headers.getMessageHeaders());
}
Aggregations