Better span names for spymemcached
MODIFY
instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/auto/instrumentation/spymemcached/CompletionListener.java
instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/auto/instrumentation/spymemcached/CompletionListener.java
@@ -29,9 +29,6 @@ import net.spy.memcached.MemcachedConnection;
@Slf4j
public abstract class CompletionListener<T> {
- // Note: it looks like this value is being ignored and DBTypeDecorator overwrites it.
- static final String OPERATION_NAME = "memcached.query";
-
static final String SERVICE_NAME = "memcached";
static final String COMPONENT_NAME = "java-spymemcached";
static final String DB_TYPE = "memcached";
@@ -40,16 +37,17 @@ public abstract class CompletionListener<T> {
static final String HIT = "hit";
static final String MISS = "miss";
- private final MemcachedConnection connection;
private final Span span;
public CompletionListener(final MemcachedConnection connection, final String methodName) {
- this.connection = connection;
- span = TRACER.spanBuilder(OPERATION_NAME).setSpanKind(CLIENT).startSpan();
+ span =
+ TRACER
+ .spanBuilder(DECORATE.spanNameOnOperation(methodName))
+ .setSpanKind(CLIENT)
+ .startSpan();
try (final Scope scope = TRACER.withSpan(span)) {
DECORATE.afterStart(span);
DECORATE.onConnection(span, connection);
- DECORATE.onOperation(span, methodName);
}
}

MODIFY
instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/auto/instrumentation/spymemcached/MemcacheClientDecorator.java
instrumentation/spymemcached-2.12/src/main/java/io/opentelemetry/auto/instrumentation/spymemcached/MemcacheClientDecorator.java
@@ -17,8 +17,6 @@ package io.opentelemetry.auto.instrumentation.spymemcached;
import io.opentelemetry.OpenTelemetry;
import io.opentelemetry.auto.bootstrap.instrumentation.decorator.DatabaseClientDecorator;
-import io.opentelemetry.auto.instrumentation.api.MoreTags;
-import io.opentelemetry.trace.Span;
import io.opentelemetry.trace.Tracer;
import net.spy.memcached.MemcachedConnection;
@@ -53,7 +51,7 @@ public class MemcacheClientDecorator extends DatabaseClientDecorator<MemcachedCo
return null;
}
- public Span onOperation(final Span span, final String methodName) {
+ public String spanNameOnOperation(final String methodName) {
final char[] chars =
methodName
@@ -65,7 +63,6 @@ public class MemcacheClientDecorator extends DatabaseClientDecorator<MemcachedCo
// Lowercase first letter
chars[0] = Character.toLowerCase(chars[0]);
- span.setAttribute(MoreTags.RESOURCE_NAME, new String(chars));
- return span;
+ return new String(chars);
}
}

MODIFY
instrumentation/spymemcached-2.12/src/test/groovy/SpymemcachedTest.groovy
instrumentation/spymemcached-2.12/src/test/groovy/SpymemcachedTest.groovy
@@ -641,13 +641,12 @@ class SpymemcachedTest extends AgentTestRunner {
childOf(trace.span(0))
}
- operationName CompletionListener.OPERATION_NAME
+ operationName operation
spanKind CLIENT
errored(error != null && error != "canceled")
tags {
"$MoreTags.SERVICE_NAME" CompletionListener.SERVICE_NAME
- "$MoreTags.RESOURCE_NAME" operation
"$Tags.COMPONENT" CompletionListener.COMPONENT_NAME
"$Tags.DB_TYPE" CompletionListener.DB_TYPE

Better span names for spymemcached (#261)