Spymemcached: add shouldStart checks (#4358)
This commit is contained in:
parent
3a90673c99
commit
57146b3ba7
|
@ -5,18 +5,30 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.spymemcached;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.spymemcached.SpymemcachedSingletons.instrumenter;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import net.spy.memcached.MemcachedConnection;
|
||||
import net.spy.memcached.internal.BulkGetFuture;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BulkGetCompletionListener extends CompletionListener<BulkGetFuture<?>>
|
||||
implements net.spy.memcached.internal.BulkGetCompletionListener {
|
||||
|
||||
public BulkGetCompletionListener(
|
||||
private BulkGetCompletionListener(Context parentContext, SpymemcachedRequest request) {
|
||||
super(parentContext, request);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static BulkGetCompletionListener create(
|
||||
Context parentContext, MemcachedConnection connection, String methodName) {
|
||||
super(parentContext, connection, methodName);
|
||||
SpymemcachedRequest request = SpymemcachedRequest.create(connection, methodName);
|
||||
if (!instrumenter().shouldStart(parentContext, request)) {
|
||||
return null;
|
||||
}
|
||||
return new BulkGetCompletionListener(parentContext, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,7 +12,6 @@ import io.opentelemetry.context.Context;
|
|||
import io.opentelemetry.instrumentation.api.config.Config;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import net.spy.memcached.MemcachedConnection;
|
||||
|
||||
public abstract class CompletionListener<T> {
|
||||
|
||||
|
@ -28,9 +27,8 @@ public abstract class CompletionListener<T> {
|
|||
private final Context context;
|
||||
private final SpymemcachedRequest request;
|
||||
|
||||
protected CompletionListener(
|
||||
Context parentContext, MemcachedConnection connection, String methodName) {
|
||||
request = SpymemcachedRequest.create(connection, methodName);
|
||||
protected CompletionListener(Context parentContext, SpymemcachedRequest request) {
|
||||
this.request = request;
|
||||
context = instrumenter().start(parentContext, request);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,17 +5,30 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.spymemcached;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.spymemcached.SpymemcachedSingletons.instrumenter;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import net.spy.memcached.MemcachedConnection;
|
||||
import net.spy.memcached.internal.GetFuture;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class GetCompletionListener extends CompletionListener<GetFuture<?>>
|
||||
implements net.spy.memcached.internal.GetCompletionListener {
|
||||
public GetCompletionListener(
|
||||
|
||||
private GetCompletionListener(Context parentContext, SpymemcachedRequest request) {
|
||||
super(parentContext, request);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static GetCompletionListener create(
|
||||
Context parentContext, MemcachedConnection connection, String methodName) {
|
||||
super(parentContext, connection, methodName);
|
||||
SpymemcachedRequest request = SpymemcachedRequest.create(connection, methodName);
|
||||
if (!instrumenter().shouldStart(parentContext, request)) {
|
||||
return null;
|
||||
}
|
||||
return new GetCompletionListener(parentContext, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -72,8 +72,11 @@ public class MemcachedClientInstrumentation implements TypeInstrumentation {
|
|||
|
||||
if (future != null) {
|
||||
OperationCompletionListener listener =
|
||||
new OperationCompletionListener(currentContext(), client.getConnection(), methodName);
|
||||
future.addListener(listener);
|
||||
OperationCompletionListener.create(
|
||||
currentContext(), client.getConnection(), methodName);
|
||||
if (listener != null) {
|
||||
future.addListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,8 +102,10 @@ public class MemcachedClientInstrumentation implements TypeInstrumentation {
|
|||
|
||||
if (future != null) {
|
||||
GetCompletionListener listener =
|
||||
new GetCompletionListener(currentContext(), client.getConnection(), methodName);
|
||||
future.addListener(listener);
|
||||
GetCompletionListener.create(currentContext(), client.getConnection(), methodName);
|
||||
if (listener != null) {
|
||||
future.addListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,8 +131,10 @@ public class MemcachedClientInstrumentation implements TypeInstrumentation {
|
|||
|
||||
if (future != null) {
|
||||
BulkGetCompletionListener listener =
|
||||
new BulkGetCompletionListener(currentContext(), client.getConnection(), methodName);
|
||||
future.addListener(listener);
|
||||
BulkGetCompletionListener.create(currentContext(), client.getConnection(), methodName);
|
||||
if (listener != null) {
|
||||
future.addListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +152,7 @@ public class MemcachedClientInstrumentation implements TypeInstrumentation {
|
|||
return null;
|
||||
}
|
||||
|
||||
return new SyncCompletionListener(currentContext(), client.getConnection(), methodName);
|
||||
return SyncCompletionListener.create(currentContext(), client.getConnection(), methodName);
|
||||
}
|
||||
|
||||
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
|
||||
|
@ -153,7 +160,7 @@ public class MemcachedClientInstrumentation implements TypeInstrumentation {
|
|||
@Advice.Enter SyncCompletionListener listener,
|
||||
@Advice.Thrown Throwable thrown,
|
||||
@Advice.Local("otelCallDepth") CallDepth callDepth) {
|
||||
if (callDepth.decrementAndGet() > 0) {
|
||||
if (callDepth.decrementAndGet() > 0 || listener == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,17 +5,30 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.spymemcached;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.spymemcached.SpymemcachedSingletons.instrumenter;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import net.spy.memcached.MemcachedConnection;
|
||||
import net.spy.memcached.internal.OperationFuture;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class OperationCompletionListener extends CompletionListener<OperationFuture<?>>
|
||||
implements net.spy.memcached.internal.OperationCompletionListener {
|
||||
public OperationCompletionListener(
|
||||
|
||||
private OperationCompletionListener(Context parentContext, SpymemcachedRequest request) {
|
||||
super(parentContext, request);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static OperationCompletionListener create(
|
||||
Context parentContext, MemcachedConnection connection, String methodName) {
|
||||
super(parentContext, connection, methodName);
|
||||
SpymemcachedRequest request = SpymemcachedRequest.create(connection, methodName);
|
||||
if (!instrumenter().shouldStart(parentContext, request)) {
|
||||
return null;
|
||||
}
|
||||
return new OperationCompletionListener(parentContext, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,9 +5,12 @@
|
|||
|
||||
package io.opentelemetry.javaagent.instrumentation.spymemcached;
|
||||
|
||||
import static io.opentelemetry.javaagent.instrumentation.spymemcached.SpymemcachedSingletons.instrumenter;
|
||||
|
||||
import io.opentelemetry.api.trace.Span;
|
||||
import io.opentelemetry.context.Context;
|
||||
import net.spy.memcached.MemcachedConnection;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -15,9 +18,18 @@ public class SyncCompletionListener extends CompletionListener<Void> {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SyncCompletionListener.class);
|
||||
|
||||
public SyncCompletionListener(
|
||||
private SyncCompletionListener(Context parentContext, SpymemcachedRequest request) {
|
||||
super(parentContext, request);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SyncCompletionListener create(
|
||||
Context parentContext, MemcachedConnection connection, String methodName) {
|
||||
super(parentContext, connection, methodName);
|
||||
SpymemcachedRequest request = SpymemcachedRequest.create(connection, methodName);
|
||||
if (!instrumenter().shouldStart(parentContext, request)) {
|
||||
return null;
|
||||
}
|
||||
return new SyncCompletionListener(parentContext, request);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue