Search in sources :

Example 1 with ClassMethodMetricNameFormat

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

the class MetricNameFormatTest method classMethodMetricNameFormat.

@Test
public void classMethodMetricNameFormat() {
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Bar", "getName()", "()V");
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", ClassMethodMetricNameFormat.getMetricName(sig, this));
    Assert.assertEquals("Test/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", ClassMethodMetricNameFormat.getMetricName(sig, this, "Test"));
    ClassMethodMetricNameFormat formatter = new ClassMethodMetricNameFormat(sig, this.getClass().getName());
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getMetricName());
    Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getTransactionSegmentName());
    Assert.assertEquals("Spring/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", new ClassMethodMetricNameFormat(sig, this.getClass().getName(), "Spring").getMetricName());
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Test(org.junit.Test)

Example 2 with ClassMethodMetricNameFormat

use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat 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 3 with ClassMethodMetricNameFormat

use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat 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 4 with ClassMethodMetricNameFormat

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

Example 5 with ClassMethodMetricNameFormat

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

the class CXFPointCut method doGetTracer.

@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, final Object servletDest, Object[] args) {
    try {
        Object endpointInfo = servletDest.getClass().getMethod("getEndpointInfo").invoke(servletDest);
        Object address = endpointInfo.getClass().getMethod("getAddress").invoke(endpointInfo);
        transaction.getInternalParameters().put(CXF_ENDPOINT_ADDRESS_PARAMETER_NAME, address);
    } catch (Throwable t) {
        Agent.LOG.log(Level.FINER, "Error parsing CXF transaction", t);
    }
    return new DefaultTracer(transaction, sig, servletDest, new ClassMethodMetricNameFormat(sig, servletDest));
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer)

Aggregations

ClassMethodMetricNameFormat (com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat)8 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)6 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)2 JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 CrossProcessConfig (com.newrelic.agent.config.CrossProcessConfig)1 Tracer (com.newrelic.agent.tracers.Tracer)1 DefaultMetricNameFormat (com.newrelic.agent.tracers.metricname.DefaultMetricNameFormat)1 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)1 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)1 MethodTracer (com.newrelic.api.agent.MethodTracer)1 Matchers.anyString (org.mockito.Matchers.anyString)1