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