diff --git a/instrumentation/vertx-core-4.5.1/src/main/java/com/nr/vertx/instrumentation/VertxCoreUtil.java b/instrumentation/vertx-core-4.5.1/src/main/java/com/nr/vertx/instrumentation/VertxCoreUtil.java index a8225d3113..12853802cc 100644 --- a/instrumentation/vertx-core-4.5.1/src/main/java/com/nr/vertx/instrumentation/VertxCoreUtil.java +++ b/instrumentation/vertx-core-4.5.1/src/main/java/com/nr/vertx/instrumentation/VertxCoreUtil.java @@ -49,6 +49,15 @@ public static void linkAndExpireToken(Listener listener) { } } + public static void expireToken(Listener listener) { + if (listener != null) { + final Token token = tokenMap.remove(listener); + if (token != null) { + token.expire(); + } + } + } + public static void processResponse(Segment segment, HttpClientResponseImpl resp, String host, int port, String scheme) { try { diff --git a/instrumentation/vertx-core-4.5.1/src/main/java/io/vertx/core/impl/future/FutureImpl_Instrumentation.java b/instrumentation/vertx-core-4.5.1/src/main/java/io/vertx/core/impl/future/FutureImpl_Instrumentation.java index 62d00f27fc..b4ac450a91 100644 --- a/instrumentation/vertx-core-4.5.1/src/main/java/io/vertx/core/impl/future/FutureImpl_Instrumentation.java +++ b/instrumentation/vertx-core-4.5.1/src/main/java/io/vertx/core/impl/future/FutureImpl_Instrumentation.java @@ -8,10 +8,13 @@ package io.vertx.core.impl.future; import com.newrelic.api.agent.Trace; +import com.newrelic.api.agent.weaver.MatchType; import com.newrelic.api.agent.weaver.Weave; import com.newrelic.api.agent.weaver.Weaver; import com.nr.vertx.instrumentation.VertxCoreUtil; +import java.util.ArrayList; + @Weave(originalName = "io.vertx.core.impl.future.FutureImpl") public abstract class FutureImpl_Instrumentation { @@ -21,12 +24,26 @@ public abstract class FutureImpl_Instrumentation { @Trace(async = true, excludeFromTransactionTrace = true) public void addListener(Listener listener) { + boolean newListenerArray = false; if (isComplete()) { VertxCoreUtil.linkAndExpireToken(listener); } else { - VertxCoreUtil.storeToken(listener); + if (this.listener == null) { + // storing a token for the first listener, which will be set in callOriginal + VertxCoreUtil.storeToken(listener); + } else if (!(this.listener instanceof ListenerArray)) { + // when a 2nd listener is added, it will convert this.listener to a ListenerArray + // so we expire the previous token, and after the ListenerArray is created, we store a token for that + VertxCoreUtil.expireToken(this.listener); + newListenerArray = true; + } } + Weaver.callOriginal(); + + if (newListenerArray) { + VertxCoreUtil.storeToken(this.listener); + } } @Trace(async = true, excludeFromTransactionTrace = true) @@ -40,4 +57,8 @@ public boolean tryFail(Throwable cause) { VertxCoreUtil.linkAndExpireToken(this.listener); return Weaver.callOriginal(); } -} + + @Weave(type = MatchType.ExactClass, originalName = "io.vertx.core.impl.future.FutureImpl$ListenerArray") + private abstract static class ListenerArray extends ArrayList> implements Listener { + } +} \ No newline at end of file