Skip to content

Commit

Permalink
#21 use redis command as span name for opentracing-redis-spring (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenZiyu authored and malafeev committed Nov 28, 2018
1 parent 5fa3e5e commit 3ab8a67
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.opentracing.Tracer;
import io.opentracing.contrib.redis.common.TracingHelper;
import io.opentracing.noop.NoopScopeManager.NoopScope;
import io.opentracing.tag.StringTag;
import io.opentracing.tag.Tags;
import java.util.function.Supplier;

Expand All @@ -35,9 +34,6 @@
*/
class RedisTracingUtils {

private static final StringTag COMMAND_TAG = new StringTag("command");
private static final String REDIS_COMMAND = "RedisCommand";

static <T> T doInScope(String command, Supplier<T> supplier, boolean withActiveSpanOnly,
Tracer tracer) {
Scope scope =
Expand All @@ -59,18 +55,17 @@ private static Scope buildScope(String command, boolean withActiveSpanOnly,
return NoopScope.INSTANCE;
}

Tracer.SpanBuilder spanBuilder = currentTracer.buildSpan(RedisTracingUtils.REDIS_COMMAND)
Tracer.SpanBuilder spanBuilder = currentTracer.buildSpan(command)
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);

Scope scope = spanBuilder.startActive(true);
decorate(scope.span(), command);
decorate(scope.span());

return scope;
}

private static void decorate(Span span, String command) {
private static void decorate(Span span) {
Tags.COMPONENT.set(span, TracingHelper.COMPONENT_NAME);
COMMAND_TAG.set(span, command);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@
*/
final class AssertionUtils {

private static final String COMMAND_TAG = "command";


/**
* Make sure we get one span once we execute a Redis command.
*/
static void commandCreatesNewSpan(MockTracer tracer, String commandName, Runnable command) {
command.run();
assertEquals(1, tracer.finishedSpans().size());
assertEquals(commandName, tracer.finishedSpans().get(0).tags().get(COMMAND_TAG));
assertEquals(commandName, tracer.finishedSpans().get(0).operationName());
tracer.reset();
}

Expand Down

0 comments on commit 3ab8a67

Please sign in to comment.