Make sure CallDepthThreadLocalMap is always reset (#1227)

Make sure CallDepthThreadLocalMap is always reset
This commit is contained in:
Tyler Benson 2020-02-21 11:03:51 -08:00 committed by GitHub
commit ecf9bcc655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 21 deletions

View File

@ -64,7 +64,7 @@ public class CouchbaseBucketInstrumentation extends Instrumenter.Default {
return CallDepthThreadLocalMap.incrementCallDepth(CouchbaseCluster.class);
}
@Advice.OnMethodExit
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void subscribeResult(
@Advice.Enter final int callDepth,
@Advice.Origin final Method method,

View File

@ -64,7 +64,7 @@ public class CouchbaseClusterInstrumentation extends Instrumenter.Default {
return CallDepthThreadLocalMap.incrementCallDepth(CouchbaseCluster.class);
}
@Advice.OnMethodExit
@Advice.OnMethodExit(onThrowable = Throwable.class)
public static void subscribeResult(
@Advice.Enter final int callDepth,
@Advice.Origin final Method method,

View File

@ -61,13 +61,13 @@ public final class PreparedStatementInstrumentation extends Instrumenter.Default
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope onEnter(@Advice.This final PreparedStatement statement) {
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(PreparedStatement.class);
if (callDepth > 0) {
final Connection connection = connectionFromStatement(statement);
if (connection == null) {
return null;
}
final Connection connection = connectionFromStatement(statement);
if (connection == null) {
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(PreparedStatement.class);
if (callDepth > 0) {
return null;
}

View File

@ -62,13 +62,13 @@ public final class StatementInstrumentation extends Instrumenter.Default {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AgentScope onEnter(
@Advice.Argument(0) final String sql, @Advice.This final Statement statement) {
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(Statement.class);
if (callDepth > 0) {
final Connection connection = connectionFromStatement(statement);
if (connection == null) {
return null;
}
final Connection connection = connectionFromStatement(statement);
if (connection == null) {
final int callDepth = CallDepthThreadLocalMap.incrementCallDepth(Statement.class);
if (callDepth > 0) {
return null;
}

View File

@ -101,7 +101,7 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
return CallDepthThreadLocalMap.incrementCallDepth(ChannelPipeline.class);
}
@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void addHandler(
@Advice.Enter final int depth,
@Advice.This final ChannelPipeline pipeline,

View File

@ -110,7 +110,7 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default {
return CallDepthThreadLocalMap.incrementCallDepth(handler.getClass());
}
@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void addHandler(
@Advice.Enter final int depth,
@Advice.This final ChannelPipeline pipeline,

View File

@ -81,14 +81,17 @@ public final class MemcachedClientInstrumentation extends Instrumenter.Default {
return CallDepthThreadLocalMap.incrementCallDepth(MemcachedClient.class) <= 0;
}
@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(
@Advice.Enter final boolean shouldInjectListener,
@Advice.This final MemcachedClient client,
@Advice.Origin("#m") final String methodName,
@Advice.Return final OperationFuture future) {
if (shouldInjectListener && future != null) {
CallDepthThreadLocalMap.reset(MemcachedClient.class);
if (!shouldInjectListener) {
return;
}
CallDepthThreadLocalMap.reset(MemcachedClient.class);
if (future != null) {
final OperationCompletionListener listener =
new OperationCompletionListener(client.getConnection(), methodName);
future.addListener(listener);
@ -103,14 +106,17 @@ public final class MemcachedClientInstrumentation extends Instrumenter.Default {
return CallDepthThreadLocalMap.incrementCallDepth(MemcachedClient.class) <= 0;
}
@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(
@Advice.Enter final boolean shouldInjectListener,
@Advice.This final MemcachedClient client,
@Advice.Origin("#m") final String methodName,
@Advice.Return final GetFuture future) {
if (shouldInjectListener && future != null) {
CallDepthThreadLocalMap.reset(MemcachedClient.class);
if (!shouldInjectListener) {
return;
}
CallDepthThreadLocalMap.reset(MemcachedClient.class);
if (future != null) {
final GetCompletionListener listener =
new GetCompletionListener(client.getConnection(), methodName);
future.addListener(listener);
@ -125,14 +131,17 @@ public final class MemcachedClientInstrumentation extends Instrumenter.Default {
return CallDepthThreadLocalMap.incrementCallDepth(MemcachedClient.class) <= 0;
}
@Advice.OnMethodExit(suppress = Throwable.class)
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void methodExit(
@Advice.Enter final boolean shouldInjectListener,
@Advice.This final MemcachedClient client,
@Advice.Origin("#m") final String methodName,
@Advice.Return final BulkFuture future) {
if (shouldInjectListener && future != null) {
CallDepthThreadLocalMap.reset(MemcachedClient.class);
if (!shouldInjectListener) {
return;
}
CallDepthThreadLocalMap.reset(MemcachedClient.class);
if (future != null) {
final BulkGetCompletionListener listener =
new BulkGetCompletionListener(client.getConnection(), methodName);
future.addListener(listener);