Better span names for spymemcached (#261)

This commit is contained in:
Trask Stalnaker 2020-03-23 09:45:33 -07:00 committed by GitHub
parent eecb4eb978
commit a101e3a5de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 14 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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