Skip to content

Commit a418735

Browse files
authored
Merge pull request #1927 from newrelic/async-handler-wrapper-vertx
Add null checks to vertx 4.5.1 instrumentation
2 parents 464aa44 + fc2a52f commit a418735

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

instrumentation/vertx-core-4.5.1/src/main/java/com/nr/vertx/instrumentation/AsyncHandlerWrapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public void handle(AsyncResult<T> event) {
2828
token.linkAndExpire();
2929
token = null;
3030
}
31-
32-
this.original.handle(event);
33-
this.original = null;
31+
if (this.original != null) {
32+
this.original.handle(event);
33+
this.original = null;
34+
}
3435
}
3536
}

instrumentation/vertx-core-4.5.1/src/main/java/io/vertx/core/impl/ContextImpl_Instrumentation.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ static <T> Future<T> executeBlocking(ContextInternal context, Handler<Promise<T>
3030
}
3131

3232
static <T> void setResultHandler(ContextInternal ctx, Future<T> fut, Handler<AsyncResult<T>> resultHandler) {
33-
Transaction txn = AgentBridge.getAgent().getTransaction(false);
34-
if (txn != null) {
35-
resultHandler = new AsyncHandlerWrapper<>(resultHandler, NewRelic.getAgent().getTransaction().getToken());
33+
if (resultHandler != null){
34+
Transaction txn = AgentBridge.getAgent().getTransaction(false);
35+
if (txn != null) {
36+
resultHandler = new AsyncHandlerWrapper<>(resultHandler, NewRelic.getAgent().getTransaction().getToken());
37+
}
3638
}
3739
Weaver.callOriginal();
3840
}

instrumentation/vertx-core-4.5.1/src/test/java/com/nr/vertx/instrumentation/VertxBlockingTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,24 @@ public void executeBlocking_withPromiseAndResult() throws InterruptedException {
4343
vertx.close();
4444
}
4545
}
46+
@Test
47+
public void executeBlocking_nullResultHandler() throws InterruptedException {
48+
//Vertx allows resultHandler to be null.
49+
Vertx vertx = Vertx.vertx();
50+
executeBlocking_nullHandler(vertx);
51+
String expectedTxnName = "OtherTransaction/Custom/com.nr.vertx.instrumentation.VertxBlockingTest/executeBlocking_nullHandler";
52+
Introspector introspector = InstrumentationTestRunner.getIntrospector();
53+
assertEquals(1, introspector.getFinishedTransactionCount(500));
54+
assertEquals(1, introspector.getTransactionEvents(expectedTxnName).size());
55+
for (TransactionEvent txnEvent: introspector.getTransactionEvents(expectedTxnName)) {
56+
Map<String, Object> attributes = txnEvent.getAttributes();
57+
assertTrue(attributes.containsKey("InFuture"));
58+
}
59+
vertx.close();
60+
}
4661

4762
@Trace(dispatcher = true)
48-
void executeBlocking(Vertx vertx) throws InterruptedException {
63+
void executeBlocking(Vertx vertx) throws InterruptedException{
4964
final CountDownLatch countDownLatch = new CountDownLatch(1);
5065
vertx.executeBlocking(future -> {
5166
NewRelic.addCustomParameter("InFuture", "yes");
@@ -56,4 +71,16 @@ void executeBlocking(Vertx vertx) throws InterruptedException {
5671
});
5772
countDownLatch.await();
5873
}
74+
75+
@Trace(dispatcher = true)
76+
void executeBlocking_nullHandler(Vertx vertx) throws InterruptedException {
77+
vertx.executeBlocking(future -> {
78+
NewRelic.addCustomParameter("InFuture", "yes");
79+
future.complete();
80+
}, null);
81+
//give the call to executeBlocking time to complete
82+
Thread.sleep(500);
83+
}
84+
85+
5986
}

0 commit comments

Comments
 (0)