Update spymemcached-2.12 to new agent api
This commit is contained in:
parent
f0c29adb61
commit
05e6544ded
|
@ -1,12 +1,13 @@
|
||||||
package datadog.trace.instrumentation.spymemcached;
|
package datadog.trace.instrumentation.spymemcached;
|
||||||
|
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import net.spy.memcached.MemcachedConnection;
|
import net.spy.memcached.MemcachedConnection;
|
||||||
import net.spy.memcached.internal.BulkGetFuture;
|
import net.spy.memcached.internal.BulkGetFuture;
|
||||||
|
|
||||||
public class BulkGetCompletionListener extends CompletionListener<BulkGetFuture<?>>
|
public class BulkGetCompletionListener extends CompletionListener<BulkGetFuture<?>>
|
||||||
implements net.spy.memcached.internal.BulkGetCompletionListener {
|
implements net.spy.memcached.internal.BulkGetCompletionListener {
|
||||||
|
|
||||||
public BulkGetCompletionListener(final MemcachedConnection connection, final String methodName) {
|
public BulkGetCompletionListener(final MemcachedConnection connection, final String methodName) {
|
||||||
super(connection, methodName);
|
super(connection, methodName);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +18,7 @@ public class BulkGetCompletionListener extends CompletionListener<BulkGetFuture<
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processResult(final Span span, final BulkGetFuture<?> future)
|
protected void processResult(final AgentSpan span, final BulkGetFuture<?> future)
|
||||||
throws ExecutionException, InterruptedException {
|
throws ExecutionException, InterruptedException {
|
||||||
/*
|
/*
|
||||||
Note: for now we do not have an affective way of representing results of bulk operations,
|
Note: for now we do not have an affective way of representing results of bulk operations,
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package datadog.trace.instrumentation.spymemcached;
|
package datadog.trace.instrumentation.spymemcached;
|
||||||
|
|
||||||
|
import static datadog.trace.instrumentation.api.AgentTracer.activateSpan;
|
||||||
|
import static datadog.trace.instrumentation.api.AgentTracer.startSpan;
|
||||||
import static datadog.trace.instrumentation.spymemcached.MemcacheClientDecorator.DECORATE;
|
import static datadog.trace.instrumentation.spymemcached.MemcacheClientDecorator.DECORATE;
|
||||||
|
|
||||||
import io.opentracing.Scope;
|
import datadog.trace.instrumentation.api.AgentScope;
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import io.opentracing.util.GlobalTracer;
|
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
@ -25,12 +26,12 @@ public abstract class CompletionListener<T> {
|
||||||
static final String MISS = "miss";
|
static final String MISS = "miss";
|
||||||
|
|
||||||
private final MemcachedConnection connection;
|
private final MemcachedConnection connection;
|
||||||
private final Span span;
|
private final AgentSpan span;
|
||||||
|
|
||||||
public CompletionListener(final MemcachedConnection connection, final String methodName) {
|
public CompletionListener(final MemcachedConnection connection, final String methodName) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
span = GlobalTracer.get().buildSpan(OPERATION_NAME).start();
|
span = startSpan(OPERATION_NAME);
|
||||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
try (final AgentScope scope = activateSpan(span, false)) {
|
||||||
DECORATE.afterStart(span);
|
DECORATE.afterStart(span);
|
||||||
DECORATE.onConnection(span, connection);
|
DECORATE.onConnection(span, connection);
|
||||||
DECORATE.onOperation(span, methodName);
|
DECORATE.onOperation(span, methodName);
|
||||||
|
@ -38,7 +39,7 @@ public abstract class CompletionListener<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void closeAsyncSpan(final T future) {
|
protected void closeAsyncSpan(final T future) {
|
||||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
try (final AgentScope scope = activateSpan(span, false)) {
|
||||||
try {
|
try {
|
||||||
processResult(span, future);
|
processResult(span, future);
|
||||||
} catch (final CancellationException e) {
|
} catch (final CancellationException e) {
|
||||||
|
@ -66,17 +67,17 @@ public abstract class CompletionListener<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void closeSyncSpan(final Throwable thrown) {
|
protected void closeSyncSpan(final Throwable thrown) {
|
||||||
try (final Scope scope = GlobalTracer.get().scopeManager().activate(span, false)) {
|
try (final AgentScope scope = activateSpan(span, false)) {
|
||||||
DECORATE.onError(span, thrown);
|
DECORATE.onError(span, thrown);
|
||||||
DECORATE.beforeFinish(span);
|
DECORATE.beforeFinish(span);
|
||||||
span.finish();
|
span.finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void processResult(Span span, T future)
|
protected abstract void processResult(AgentSpan span, T future)
|
||||||
throws ExecutionException, InterruptedException;
|
throws ExecutionException, InterruptedException;
|
||||||
|
|
||||||
protected void setResultTag(final Span span, final boolean hit) {
|
protected void setResultTag(final AgentSpan span, final boolean hit) {
|
||||||
span.setTag(MEMCACHED_RESULT, hit ? HIT : MISS);
|
span.setTag(MEMCACHED_RESULT, hit ? HIT : MISS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package datadog.trace.instrumentation.spymemcached;
|
package datadog.trace.instrumentation.spymemcached;
|
||||||
|
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import net.spy.memcached.MemcachedConnection;
|
import net.spy.memcached.MemcachedConnection;
|
||||||
import net.spy.memcached.internal.GetFuture;
|
import net.spy.memcached.internal.GetFuture;
|
||||||
|
@ -17,7 +17,7 @@ public class GetCompletionListener extends CompletionListener<GetFuture<?>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processResult(final Span span, final GetFuture<?> future)
|
protected void processResult(final AgentSpan span, final GetFuture<?> future)
|
||||||
throws ExecutionException, InterruptedException {
|
throws ExecutionException, InterruptedException {
|
||||||
final Object result = future.get();
|
final Object result = future.get();
|
||||||
setResultTag(span, result != null);
|
setResultTag(span, result != null);
|
||||||
|
|
|
@ -3,7 +3,7 @@ package datadog.trace.instrumentation.spymemcached;
|
||||||
import datadog.trace.agent.decorator.DatabaseClientDecorator;
|
import datadog.trace.agent.decorator.DatabaseClientDecorator;
|
||||||
import datadog.trace.api.DDSpanTypes;
|
import datadog.trace.api.DDSpanTypes;
|
||||||
import datadog.trace.api.DDTags;
|
import datadog.trace.api.DDTags;
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import net.spy.memcached.MemcachedConnection;
|
import net.spy.memcached.MemcachedConnection;
|
||||||
|
|
||||||
public class MemcacheClientDecorator extends DatabaseClientDecorator<MemcachedConnection> {
|
public class MemcacheClientDecorator extends DatabaseClientDecorator<MemcachedConnection> {
|
||||||
|
@ -44,7 +44,7 @@ public class MemcacheClientDecorator extends DatabaseClientDecorator<MemcachedCo
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span onOperation(final Span span, final String methodName) {
|
public AgentSpan onOperation(final AgentSpan span, final String methodName) {
|
||||||
|
|
||||||
final char[] chars =
|
final char[] chars =
|
||||||
methodName
|
methodName
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package datadog.trace.instrumentation.spymemcached;
|
package datadog.trace.instrumentation.spymemcached;
|
||||||
|
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import net.spy.memcached.MemcachedConnection;
|
import net.spy.memcached.MemcachedConnection;
|
||||||
import net.spy.memcached.internal.OperationFuture;
|
import net.spy.memcached.internal.OperationFuture;
|
||||||
|
@ -19,7 +19,7 @@ public class OperationCompletionListener
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processResult(final Span span, final OperationFuture<? extends Object> future)
|
protected void processResult(final AgentSpan span, final OperationFuture<? extends Object> future)
|
||||||
throws ExecutionException, InterruptedException {
|
throws ExecutionException, InterruptedException {
|
||||||
future.get();
|
future.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package datadog.trace.instrumentation.spymemcached;
|
package datadog.trace.instrumentation.spymemcached;
|
||||||
|
|
||||||
import io.opentracing.Span;
|
import datadog.trace.instrumentation.api.AgentSpan;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.spy.memcached.MemcachedConnection;
|
import net.spy.memcached.MemcachedConnection;
|
||||||
|
@ -12,7 +12,7 @@ public class SyncCompletionListener extends CompletionListener<Void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processResult(final Span span, final Void future)
|
protected void processResult(final AgentSpan span, final Void future)
|
||||||
throws ExecutionException, InterruptedException {
|
throws ExecutionException, InterruptedException {
|
||||||
log.error("processResult was called on SyncCompletionListener. This should never happen. ");
|
log.error("processResult was called on SyncCompletionListener. This should never happen. ");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue