Search in sources :

Example 1 with TraceContextProvider

use of io.lettuce.core.tracing.TraceContextProvider in project lettuce-core by lettuce-io.

the class CommandHandler method attachTracing.

private void attachTracing(ChannelHandlerContext ctx, RedisCommand<?, ?, ?> command) {
    if (!tracingEnabled || !(command instanceof CompleteableCommand)) {
        return;
    }
    TracedCommand<?, ?, ?> traced = CommandWrapper.unwrap(command, TracedCommand.class);
    TraceContextProvider provider = (traced == null ? clientResources.tracing().initialTraceContextProvider() : traced);
    Tracer tracer = clientResources.tracing().getTracerProvider().getTracer();
    if (provider != null) {
        TraceContext context = provider.getTraceContext();
        Tracer.Span span = tracer.nextSpan(context);
        span.name(command.getType().name());
        if (tracedEndpoint != null) {
            span.remoteEndpoint(tracedEndpoint);
        } else {
            span.remoteEndpoint(clientResources.tracing().createEndpoint(ctx.channel().remoteAddress()));
        }
        span.start(command);
        if (traced != null) {
            traced.setSpan(span);
        }
    }
}
Also used : TraceContextProvider(io.lettuce.core.tracing.TraceContextProvider) Tracer(io.lettuce.core.tracing.Tracer) TraceContext(io.lettuce.core.tracing.TraceContext)

Example 2 with TraceContextProvider

use of io.lettuce.core.tracing.TraceContextProvider in project lettuce-core by lettuce-io.

the class RedisChannelHandler method dispatch.

protected Collection<RedisCommand<K, V, ?>> dispatch(Collection<? extends RedisCommand<K, V, ?>> commands) {
    if (debugEnabled) {
        logger.debug("dispatching commands {}", commands);
    }
    if (tracingEnabled) {
        Collection<RedisCommand<K, V, ?>> withTracer = new ArrayList<>(commands.size());
        for (RedisCommand<K, V, ?> command : commands) {
            RedisCommand<K, V, ?> commandToUse = command;
            TraceContextProvider provider = CommandWrapper.unwrap(command, TraceContextProvider.class);
            if (provider == null) {
                commandToUse = new TracedCommand<>(command, clientResources.tracing().initialTraceContextProvider().getTraceContext());
            }
            withTracer.add(commandToUse);
        }
        return channelWriter.write(withTracer);
    }
    return channelWriter.write(commands);
}
Also used : TraceContextProvider(io.lettuce.core.tracing.TraceContextProvider) RedisCommand(io.lettuce.core.protocol.RedisCommand) ArrayList(java.util.ArrayList)

Example 3 with TraceContextProvider

use of io.lettuce.core.tracing.TraceContextProvider in project lettuce-core by lettuce-io.

the class RedisChannelHandler method dispatch.

protected <T> RedisCommand<K, V, T> dispatch(RedisCommand<K, V, T> cmd) {
    if (debugEnabled) {
        logger.debug("dispatching command {}", cmd);
    }
    if (tracingEnabled) {
        RedisCommand<K, V, T> commandToSend = cmd;
        TraceContextProvider provider = CommandWrapper.unwrap(cmd, TraceContextProvider.class);
        if (provider == null) {
            commandToSend = new TracedCommand<>(cmd, clientResources.tracing().initialTraceContextProvider().getTraceContext());
        }
        return channelWriter.write(commandToSend);
    }
    return channelWriter.write(cmd);
}
Also used : TraceContextProvider(io.lettuce.core.tracing.TraceContextProvider)

Aggregations

TraceContextProvider (io.lettuce.core.tracing.TraceContextProvider)3 RedisCommand (io.lettuce.core.protocol.RedisCommand)1 TraceContext (io.lettuce.core.tracing.TraceContext)1 Tracer (io.lettuce.core.tracing.Tracer)1 ArrayList (java.util.ArrayList)1