Search in sources :

Example 16 with DefaultTracer

use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.

the class JsonTracer method generateDefaultTracer.

private DefaultTracer generateDefaultTracer(long txaStartTime) {
    ClassMethodSignature sig = new ClassMethodSignature("clazz", tracerName, "()");
    Object reference = new Object();
    DefaultTracer tracer = new DefaultTracer(Transaction.getTransaction().getTransactionActivity(), sig, reference, new ClassMethodMetricNameFormat(sig, reference), txaStartTime + startTimeNs);
    Transaction.getTransaction().getTransactionActivity().tracerStarted(tracer);
    return tracer;
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) JSONObject(org.json.simple.JSONObject)

Example 17 with DefaultTracer

use of com.newrelic.agent.tracers.DefaultTracer 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)

Example 18 with DefaultTracer

use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.

the class HandlerMethodInvokerPointCut method doGetTracer.

@Override
public Tracer doGetTracer(final Transaction transaction, ClassMethodSignature sig, Object invoker, final Object[] args) {
    final String methodName = ((Method) args[0]).getName();
    final Class controller = args[1].getClass();
    setTransactionName(transaction, methodName, controller);
    if (SPRING_3X_METHOD.equals(sig.getMethodName())) {
        // we do not want to time the spring 3X method
        return null;
    } else {
        return new DefaultTracer(transaction, sig, invoker, new SimpleMetricNameFormat("Spring/Java/" + controller.getName() + '/' + methodName)) {

            @Override
            protected void doFinish(Throwable throwable) {
                // okay, this is our best chance at normalizing this
                setTransactionName(transaction, methodName, controller);
            }
        };
    }
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Method(java.lang.reflect.Method) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 19 with DefaultTracer

use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.

the class SpringPointCut method doGetTracer.

@Override
public Tracer doGetTracer(final Transaction transaction, final ClassMethodSignature sig, final Object controller, Object[] args) {
    final Object handler = args[2];
    return new DefaultTracer(transaction, sig, controller) {

        @Override
        protected void doFinish(int opcode, Object modelView) {
            String metricName;
            if (handler != null) {
                StringBuilder tracerName = new StringBuilder("SpringController/");
                tracerName.append(getControllerName(handler.getClass()));
                metricName = tracerName.toString();
            } else {
                StringBuilder tracerName = new StringBuilder("SpringController/");
                tracerName.append(getControllerName(controller.getClass()));
                tracerName.append('/').append(sig.getMethodName());
                metricName = tracerName.toString();
            }
            setMetricNameFormat(new SimpleMetricNameFormat(metricName));
            super.doFinish(opcode, modelView);
        }

        private String getControllerName(Class<?> controller) {
            String controllerName = controller.getName();
            int indexOf = controllerName.indexOf(MethodInvokerPointCut.TO_REMOVE);
            if (indexOf > 0) {
                controllerName = controllerName.substring(0, indexOf);
            }
            return controllerName;
        }

        private void setTransactionName(Transaction transaction, Object modelView) {
            if (!transaction.isTransactionNamingEnabled()) {
                return;
            }
            TransactionNamingPolicy policy = TransactionNamingPolicy.getHigherPriorityTransactionNamingPolicy();
            if (policy.canSetTransactionName(transaction, TransactionNamePriority.FRAMEWORK)) {
                String modelAndViewName = doGetModelAndViewName(modelView);
                if (modelAndViewName == null) {
                    return;
                }
                if (Agent.LOG.isLoggable(Level.FINER)) {
                    String msg = MessageFormat.format("Setting transaction name to \"{0}\" using Spring ModelView", modelAndViewName);
                    Agent.LOG.finer(msg);
                }
                policy.setTransactionName(transaction, modelAndViewName, SPRING_VIEW, TransactionNamePriority.FRAMEWORK);
            }
        }

        private String doGetModelAndViewName(Object modelAndView) {
            try {
                return getModelAndViewViewName(modelAndView);
            } catch (Exception e) {
                Agent.LOG.log(Level.FINE, "Unable to parse Spring ModelView", e);
            }
            return null;
        }
    };
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Transaction(com.newrelic.agent.Transaction) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) TransactionNamingPolicy(com.newrelic.agent.transaction.TransactionNamingPolicy) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 20 with DefaultTracer

use of com.newrelic.agent.tracers.DefaultTracer in project newrelic-java-agent by newrelic.

the class Struts2ActionPointCut method doGetTracer.

@Override
public Tracer doGetTracer(Transaction tx, ClassMethodSignature sig, Object action, Object[] args) {
    try {
        String realAction;
        if (action instanceof ActionProxy) {
            realAction = ((ActionProxy) action).getActionName();
        } else {
            realAction = (String) action.getClass().getMethod("getActionName").invoke(action);
        }
        setTransactionName(tx, realAction);
        return new DefaultTracer(tx, sig, action, new SimpleMetricNameFormat(MetricNames.STRUTS_ACTION_PREFIX + realAction));
    } catch (Exception e) {
        return new DefaultTracer(tx, sig, action, new ClassMethodMetricNameFormat(sig, action, MetricNames.STRUTS_ACTION));
    }
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Aggregations

DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)46 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)24 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)20 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)19 Transaction (com.newrelic.agent.Transaction)17 Tracer (com.newrelic.agent.tracers.Tracer)16 Test (org.junit.Test)14 TransactionData (com.newrelic.agent.TransactionData)6 ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)6 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)6 SqlTraceConfig (com.newrelic.agent.config.SqlTraceConfig)5 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)5 JSONObject (org.json.simple.JSONObject)5 MockDispatcher (com.newrelic.agent.MockDispatcher)4 DefaultSqlTracer (com.newrelic.agent.tracers.DefaultSqlTracer)4 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)4 HashMap (java.util.HashMap)4 TransactionActivity (com.newrelic.agent.TransactionActivity)3 ExitTracer (com.newrelic.agent.bridge.ExitTracer)3 ServerProp (com.newrelic.agent.config.ServerProp)3