Search in sources :

Example 1 with ServerSpan

use of com.github.kristofa.brave.ServerSpan in project zipkin by openzipkin.

the class TraceZipkinMySQLStorageAutoConfiguration method executor.

@Bean
@ConditionalOnMissingBean(Executor.class)
public Executor executor(ServerSpanState serverState) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("MySQLStorage-");
    executor.initialize();
    return command -> {
        ServerSpan currentSpan = serverState.getCurrentServerSpan();
        executor.execute(() -> {
            serverState.setCurrentServerSpan(currentSpan);
            command.run();
        });
    };
}
Also used : ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ZipkinMySQLStorageProperties(zipkin.autoconfigure.storage.mysql.ZipkinMySQLStorageProperties) Executor(java.util.concurrent.Executor) Brave(com.github.kristofa.brave.Brave) ServerSpanState(com.github.kristofa.brave.ServerSpanState) Endpoint(com.twitter.zipkin.gen.Endpoint) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.jooq.tools.StringUtils) ServerSpan(com.github.kristofa.brave.ServerSpan) UnknownHostException(java.net.UnknownHostException) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) Configuration(org.springframework.context.annotation.Configuration) ExecuteContext(org.jooq.ExecuteContext) DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) Qualifier(org.springframework.beans.factory.annotation.Qualifier) SQL_QUERY(zipkin.TraceKeys.SQL_QUERY) ExecuteListenerProvider(org.jooq.ExecuteListenerProvider) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) ServerSpan(com.github.kristofa.brave.ServerSpan) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ServerSpan

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

Example 3 with ServerSpan

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

Example 4 with ServerSpan

use of com.github.kristofa.brave.ServerSpan 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

ServerSpan (com.github.kristofa.brave.ServerSpan)4 ServerSpanThreadBinder (com.github.kristofa.brave.ServerSpanThreadBinder)3 Brave (com.github.kristofa.brave.Brave)1 ClientSpanThreadBinder (com.github.kristofa.brave.ClientSpanThreadBinder)1 ServerSpanState (com.github.kristofa.brave.ServerSpanState)1 Endpoint (com.twitter.zipkin.gen.Endpoint)1 Span (com.twitter.zipkin.gen.Span)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 Executor (java.util.concurrent.Executor)1 ExecuteContext (org.jooq.ExecuteContext)1 ExecuteListenerProvider (org.jooq.ExecuteListenerProvider)1 DefaultExecuteListener (org.jooq.impl.DefaultExecuteListener)1 DefaultExecuteListenerProvider (org.jooq.impl.DefaultExecuteListenerProvider)1 StringUtils (org.jooq.tools.StringUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1