rabbit;
import com.github.kristofa.brave.*;
import com.github.nightawk.core.util.Headers;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import java.util.Collection;
import java.util.Collections;
/**
* @author xs.
*/
public class TracingMessageListenerContainer extends SimpleMessageListenerContainer
{
@Override
public TraceData getTraceData() {
MessageProperties messageProperties = message.getMessageProperties();
final String sampled = (String)
messageProperties.getHeaders().get(Headers.Sampled.getName());
if (sampled != null) {
if (sampled.equals("0") || sampled.toLowerCase().equals("false")) {
return TraceData.builder().sample(false).build();
} else {
final String parentSpanId = (String)
messageProperties.getHeaders().get(Headers.ParentSpanId.getName());
final String traceId = (String)
messageProperties.getHeaders().get(Headers.TraceId.getName());
final String spanId = (String)
messageProperties.getHeaders().get(Headers.SpanId.getName());
@Override
public String getSpanName() {
return "rabbit-mq";
}
@Override
public Collection<KeyValueAnnotation> requestAnnotations() {
return Collections.emptyList();
}
@Override
public Collection<KeyValueAnnotation> responseAnnotations() {
return Collections.emptyList();
}
}
}