Search in sources :

Example 1 with MethodTracer

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);
                }
            };
        }
    }
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) MethodTracer(com.newrelic.api.agent.MethodTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) MethodTracer(com.newrelic.api.agent.MethodTracer) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Aggregations

DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)1 Tracer (com.newrelic.agent.tracers.Tracer)1 ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)1 MethodTracer (com.newrelic.api.agent.MethodTracer)1