use of brave.propagation.TraceContextOrSamplingFlags in project spring-cloud-sleuth by spring-cloud.
the class TracingChannelInterceptor method preSend.
/**
* Starts and propagates {@link Span.Kind#PRODUCER} span for each message sent.
*/
@Override
public Message<?> preSend(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.PRODUCER).name("send").start();
span.remoteEndpoint(Endpoint.newBuilder().serviceName(REMOTE_SERVICE_NAME).build());
addTags(message, span, channel);
}
if (log.isDebugEnabled()) {
log.debug("Created a new span in pre send" + span);
}
headers.setImmutable();
Message<?> outputMessage = new GenericMessage<>(message.getPayload(), headers.getMessageHeaders());
if (isDirectChannel(channel)) {
beforeHandle(outputMessage, channel, null);
}
return outputMessage;
}
use of brave.propagation.TraceContextOrSamplingFlags in project spring-cloud-sleuth by spring-cloud.
the class TracingChannelInterceptor method nextSpan.
/**
* Use this to create a span for processing the given message. Note: the result has no name and is
* not started.
* <p>
* <p>This creates a child from identifiers extracted from the message headers, or a new span if
* one couldn't be extracted.
*/
public Span nextSpan(Message<?> message) {
MessageHeaderAccessor headers = mutableHeaderAccessor(message);
TraceContextOrSamplingFlags extracted = this.extractor.extract(headers);
headers.setImmutable();
Span result = this.tracer.nextSpan(extracted);
if (extracted.context() == null && !result.isNoop()) {
addTags(message, result, null);
}
if (log.isDebugEnabled()) {
log.debug("Created a new span " + result);
}
return result;
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracingServerInterceptor method interceptCall.
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(final ServerCall<ReqT, RespT> call, final Metadata headers, final ServerCallHandler<ReqT, RespT> next) {
TraceContextOrSamplingFlags extracted = extractor.extract(headers);
Span span = extracted.context() != null ? tracer.joinSpan(extracted.context()) : tracer.nextSpan(extracted);
span.kind(Span.Kind.SERVER);
parser.onStart(call, headers, span.customizer());
// startCall invokes user interceptors, so we place the span in scope here
ServerCall.Listener<ReqT> result;
try (Tracer.SpanInScope ws = tracer.withSpanInScope(span)) {
result = next.startCall(new TracingServerCall<>(span, call, parser), headers);
} catch (RuntimeException | Error e) {
parser.onError(e, span.customizer());
span.finish();
throw e;
}
// This ensures the server implementation can see the span in scope
return new ScopingServerCallListener<>(tracer, span, result, parser);
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class KafkaTracing method joinSpan.
/**
* Retrieve the span extracted from the record headers. Creates a root span if the context is not
* available.
*
* @deprecated this results in appending to a span already complete. Please use {@link
* #nextSpan(ConsumerRecord)}
*/
@Deprecated
public Span joinSpan(ConsumerRecord<?, ?> record) {
TraceContextOrSamplingFlags extracted = extractAndClearHeaders(record);
if (extracted.context() != null) {
// avoid creating an unnecessary child
return tracing.tracer().toSpan(extracted.context());
}
Span result = tracing.tracer().nextSpan(extracted);
if (!result.isNoop())
addTags(record, result.customizer());
return result;
}
use of brave.propagation.TraceContextOrSamplingFlags in project brave by openzipkin.
the class TracingRabbitListenerAdvice method extractTraceContextAndRemoveHeaders.
TraceContextOrSamplingFlags extractTraceContextAndRemoveHeaders(Message message) {
MessageProperties messageProperties = message.getMessageProperties();
TraceContextOrSamplingFlags extracted = extractor.extract(messageProperties);
Map<String, Object> headers = messageProperties.getHeaders();
for (String key : tracing.propagation().keys()) {
headers.remove(key);
}
return extracted;
}
Aggregations