[Java] Dispatch new transaction from existing one

Hi, i want to dispatch a separate transaction from existing one.
I tried with @Trace(metricName = “name” , dispatcher = true) but didn’t work. In the documentation explain this ‘When this annotation is used on a method within the context of an existing transaction, this will not start a new transaction’.
I have a bach process (the principal transaction), that can call many times to a method ‘X’, who have an @Trace. So, i want register this new transaction with his own info.
I use new relic api 4.11.
Is any chance to do this with api annotations?

The Java agent has an Async API https://docs.newrelic.com/docs/agents/java-agent/async-instrumentation/introduction-java-async-instrumentation

Hi Jeani, i tried with async api but i obtained the same result.
I have a code like this :
Method in some class
private String methodA() {
doSomething…
for x to y {
doSomethingElse…
NewRelicHelper.recordOnNewTransaction(a,b ,c)
doSomethingElseAgan…
}
}

NewRelicHelper
@Trace(metricName = ‘newTransactioName’ , async = true, dispatcher = true)
public static void recordOnNewTransaction(String a, String b, String c) {
NewRelic.addCustomParameter(NewRelicConstants.A, a);
NewRelic.addCustomParameter(NewRelicConstants.B, b);
NewRelic.addCustomParameter(NewRelicConstants.C, c);
}

But never see a new transaction with name newTransactioName. I see the attr in the father’s transaction (only the last one).
Is posible that this can never occur? Is possible create another transaction separated of the original? I’m a little lost about it.

Thanks in advace.

Hello @cagrazar,

Thanks for providing a code sample. You may need to use getToken() and token.expire() to make sure that the Transaction has a start and end time. If the token isn’t expired properly, it can time out and never be returned to New Relic.

Also, you can check if you’re capturing the transaction by setting the logging level to FINEST and look for messages related to setting Transaction name.

More example can be found here: