use of com.github.kristofa.brave.ServerSpanThreadBinder in project camel by apache.
the class ZipkinTracer method serverResponse.
private void serverResponse(Brave brave, String serviceName, Exchange exchange) {
ServerSpan span = null;
ZipkinState state = exchange.getProperty(ZipkinState.KEY, ZipkinState.class);
if (state != null) {
// only process if it was a zipkin server event
span = state.popServerSpan();
}
if (span != null) {
ServerSpanThreadBinder serverBinder = brave.serverSpanThreadBinder();
serverBinder.setCurrentSpan(span);
brave.serverResponseInterceptor().handle(new ZipkinServerResponseAdapter(this, exchange));
// and reset binder
serverBinder.setCurrentSpan(null);
if (span.getSpan() != null && LOG.isDebugEnabled()) {
String traceId = "" + span.getSpan().getTrace_id();
String spanId = "" + span.getSpan().getId();
String parentId = span.getSpan().getParent_id() != null ? "" + span.getSpan().getParent_id() : null;
if (LOG.isDebugEnabled()) {
if (parentId != null) {
LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
} else {
LOG.debug(String.format("serverResponse[service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
}
}
}
}
}
use of com.github.kristofa.brave.ServerSpanThreadBinder in project camel by apache.
the class ZipkinTracer method serverRequest.
private ServerSpan serverRequest(Brave brave, String serviceName, Exchange exchange) {
ServerSpanThreadBinder serverBinder = brave.serverSpanThreadBinder();
// reuse existing span if we do multiple requests from the same
ZipkinState state = exchange.getProperty(ZipkinState.KEY, ZipkinState.class);
if (state == null) {
state = new ZipkinState();
exchange.setProperty(ZipkinState.KEY, state);
}
// if we started from a another server span then lets reuse that
ServerSpan last = state.peekServerSpan();
if (last != null) {
serverBinder.setCurrentSpan(last);
}
brave.serverRequestInterceptor().handle(new ZipkinServerRequestAdapter(this, exchange));
// store span after request
ServerSpan span = serverBinder.getCurrentServerSpan();
state.pushServerSpan(span);
// and reset binder
serverBinder.setCurrentSpan(null);
if (span != null && span.getSpan() != null && LOG.isDebugEnabled()) {
String traceId = "" + span.getSpan().getTrace_id();
String spanId = "" + span.getSpan().getId();
String parentId = span.getSpan().getParent_id() != null ? "" + span.getSpan().getParent_id() : null;
if (LOG.isDebugEnabled()) {
if (parentId != null) {
LOG.debug(String.format("serverRequest [service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
} else {
LOG.debug(String.format("serverRequest [service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
}
}
}
return span;
}
use of com.github.kristofa.brave.ServerSpanThreadBinder in project camel by apache.
the class ZipkinTracer method clientRequest.
private void clientRequest(Brave brave, String serviceName, ExchangeSendingEvent event) {
ClientSpanThreadBinder clientBinder = brave.clientSpanThreadBinder();
ServerSpanThreadBinder serverBinder = brave.serverSpanThreadBinder();
// reuse existing span if we do multiple requests from the same
ZipkinState state = event.getExchange().getProperty(ZipkinState.KEY, ZipkinState.class);
if (state == null) {
state = new ZipkinState();
event.getExchange().setProperty(ZipkinState.KEY, state);
}
// if we started from a server span then lets reuse that when we call a downstream service
ServerSpan last = state.peekServerSpan();
if (last != null) {
serverBinder.setCurrentSpan(last);
}
brave.clientRequestInterceptor().handle(new ZipkinClientRequestAdapter(this, serviceName, event.getExchange(), event.getEndpoint()));
// store span after request
Span span = clientBinder.getCurrentClientSpan();
state.pushClientSpan(span);
// and reset binder
clientBinder.setCurrentSpan(null);
serverBinder.setCurrentSpan(null);
if (span != null && LOG.isDebugEnabled()) {
String traceId = "" + span.getTrace_id();
String spanId = "" + span.getId();
String parentId = span.getParent_id() != null ? "" + span.getParent_id() : null;
if (LOG.isDebugEnabled()) {
if (parentId != null) {
LOG.debug(String.format("clientRequest [service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
} else {
LOG.debug(String.format("clientRequest [service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
}
}
}
}
Aggregations