Search in sources :

Example 51 with SimpleMetricNameFormat

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

the class RequestUriConfigTests method startTracer.

private DefaultTracer startTracer() throws SQLException {
    DummyConnection conn = new DummyConnection();
    Statement statement = conn.createStatement();
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    DefaultTracer tracer = new OtherRootTracer(tx, sig, statement, new SimpleMetricNameFormat("metric", "segment", "some uri")) {

        @Override
        public long getDuration() {
            return 100000;
        }
    };
    tx.getTransactionActivity().tracerStarted(tracer);
    return tracer;
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Statement(java.sql.Statement) DummyConnection(sql.DummyConnection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 52 with SimpleMetricNameFormat

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

the class CustomTracerFactoryTest method testNoTracerWithParent.

@Test
public void testNoTracerWithParent() {
    Transaction transaction = Transaction.getTransaction();
    transaction.getTransactionActivity().tracerStarted(new OtherRootTracer(transaction, signature, this, new SimpleMetricNameFormat("test")));
    NoTracerMethodTracerFactory mtf = new NoTracerMethodTracerFactory();
    CustomTracerFactory factory = new CustomTracerFactory(mtf);
    Tracer tracer = factory.getTracer(transaction, signature, this, new Object[0]);
    Assert.assertFalse(tracer instanceof TransactionActivityInitiator);
    Assert.assertEquals(1, mtf.invocationCount);
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) MethodTracer(com.newrelic.api.agent.MethodTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 53 with SimpleMetricNameFormat

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

the class XWork2ResultPC method doGetTracer.

@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, Object result, Object[] args) {
    String name;
    try {
        Object action;
        if (args[0] instanceof ActionInvocation) {
            action = ((ActionInvocation) args[0]).getAction();
        } else {
            action = args[0].getClass().getMethod("getAction").invoke(args[0]);
        }
        name = action.getClass().getName();
    } catch (Throwable t) {
        name = "Unknown";
    }
    return new DefaultTracer(transaction, sig, result, new SimpleMetricNameFormat("StrutsResult/" + name));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 54 with SimpleMetricNameFormat

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

the class HandleInternalInvokerPointCut method doGetTracer.

@Override
public Tracer doGetTracer(final Transaction transaction, ClassMethodSignature sig, Object invoker, final Object[] args) {
    String methodName = null;
    Class<?> controller = null;
    StringBuilder tracerName = new StringBuilder("Spring/Java");
    // grab the information we need
    try {
        HandlerMethod methodInfo = (HandlerMethod) args[2];
        methodName = methodInfo._nr_getBridgedMethod().getName();
        controller = methodInfo._nr_getBean().getClass();
        // build the tracer name;
        tracerName.append(getControllerName(methodName, controller));
        setTransactionName(transaction, methodName, controller);
    } catch (Exception e) {
        // if it fails use the method name
        Agent.LOG.log(Level.FINE, "Unable to pull controller and method from spring framework.");
        Agent.LOG.log(Level.FINEST, "Exception grabbing spring controller.", e);
        tracerName.append(sig.getMethodName());
    }
    return new DefaultTracer(transaction, sig, invoker, new SimpleMetricNameFormat(tracerName.toString()));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 55 with SimpleMetricNameFormat

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

the class HandlerMethodInvoker3PointCut method doGetTracer.

@Override
public Tracer doGetTracer(final Transaction transaction, ClassMethodSignature sig, Object invoker, final Object[] args) {
    StringBuilder tracerName = new StringBuilder("Spring/Java");
    String methodName = ((Method) args[0]).getName();
    Class<?> controller = args[1].getClass();
    // build the tracer name;
    tracerName.append(getControllerName(methodName, controller));
    return new DefaultTracer(transaction, sig, invoker, new SimpleMetricNameFormat(tracerName.toString()));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Method(java.lang.reflect.Method) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Aggregations

SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)70 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)46 Transaction (com.newrelic.agent.Transaction)43 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)34 Test (org.junit.Test)32 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)11 Response (com.newrelic.api.agent.Response)10 Tracer (com.newrelic.agent.tracers.Tracer)9 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)9 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)8 Request (com.newrelic.api.agent.Request)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)8 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)8 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)8 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)7 TransactionDataList (com.newrelic.agent.TransactionDataList)6