Search in sources :

Example 1 with ClientSpanThreadBinder

use of com.github.kristofa.brave.ClientSpanThreadBinder in project camel by apache.

the class ZipkinTracer method clientResponse.

private void clientResponse(Brave brave, String serviceName, ExchangeSentEvent event) {
    Span span = null;
    ZipkinState state = event.getExchange().getProperty(ZipkinState.KEY, ZipkinState.class);
    if (state != null) {
        // only process if it was a zipkin client event
        span = state.popClientSpan();
    }
    if (span != null) {
        ClientSpanThreadBinder clientBinder = brave.clientSpanThreadBinder();
        clientBinder.setCurrentSpan(span);
        brave.clientResponseInterceptor().handle(new ZipkinClientResponseAdaptor(this, event.getExchange(), event.getEndpoint()));
        // and reset binder
        clientBinder.setCurrentSpan(null);
        if (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("clientResponse[service=%s, traceId=%20s, spanId=%20s, parentId=%20s]", serviceName, traceId, spanId, parentId));
                } else {
                    LOG.debug(String.format("clientResponse[service=%s, traceId=%20s, spanId=%20s]", serviceName, traceId, spanId));
                }
            }
        }
    }
}
Also used : ClientSpanThreadBinder(com.github.kristofa.brave.ClientSpanThreadBinder) Span(com.twitter.zipkin.gen.Span) ServerSpan(com.github.kristofa.brave.ServerSpan)

Example 2 with ClientSpanThreadBinder

use of com.github.kristofa.brave.ClientSpanThreadBinder 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));
            }
        }
    }
}
Also used : ServerSpan(com.github.kristofa.brave.ServerSpan) ClientSpanThreadBinder(com.github.kristofa.brave.ClientSpanThreadBinder) ServerSpanThreadBinder(com.github.kristofa.brave.ServerSpanThreadBinder) Span(com.twitter.zipkin.gen.Span) ServerSpan(com.github.kristofa.brave.ServerSpan)

Aggregations

ClientSpanThreadBinder (com.github.kristofa.brave.ClientSpanThreadBinder)2 ServerSpan (com.github.kristofa.brave.ServerSpan)2 Span (com.twitter.zipkin.gen.Span)2 ServerSpanThreadBinder (com.github.kristofa.brave.ServerSpanThreadBinder)1