use of com.newrelic.api.agent.MethodTracer in project newrelic-java-agent by newrelic.
the class CustomTracerFactory method doGetTracer.
@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, Object object, Object[] args) {
Tracer parent = transaction.getTransactionActivity().getLastTracer();
final MethodTracer methodTracer = tracerFactory.methodInvoked(sig.getMethodName(), object, args);
// no custom method tracer, just hook up a normal tracer
if (methodTracer == null) {
return parent == null ? new OtherRootTracer(transaction, sig, object, new ClassMethodMetricNameFormat(sig, object)) : new DefaultTracer(transaction, sig, object);
} else // otherwise we have to let the method tracer know when the method exits
{
// DefaultTracer. This is the safest way to implement this for now.
if (parent == null) {
return new OtherRootTracer(transaction, sig, object, new ClassMethodMetricNameFormat(sig, object)) {
@Override
protected void doFinish(Throwable throwable) {
super.doFinish(throwable);
methodTracer.methodFinishedWithException(throwable);
}
@Override
protected void doFinish(int opcode, Object returnValue) {
super.doFinish(opcode, returnValue);
methodTracer.methodFinished(returnValue);
}
};
} else {
return new DefaultTracer(transaction, sig, object) {
@Override
protected void doFinish(Throwable throwable) {
super.doFinish(throwable);
methodTracer.methodFinishedWithException(throwable);
}
@Override
protected void doFinish(int opcode, Object returnValue) {
super.doFinish(opcode, returnValue);
methodTracer.methodFinished(returnValue);
}
};
}
}
}
Aggregations