Search in sources :

Example 21 with SimpleMetricNameFormat

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

the class ApiTest method testIgnoreTransaction.

@Test
public void testIgnoreTransaction() {
    Transaction tx = Transaction.getTransaction();
    tx.getTransactionActivity().tracerStarted(new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("dude")));
    NewRelic.ignoreTransaction();
    Assert.assertTrue("Transaction should be ignored", tx.isIgnore());
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 22 with SimpleMetricNameFormat

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

the class CustomTracerFactoryTest method testTracerWithParent.

@Test
public void testTracerWithParent() {
    Transaction transaction = Transaction.getTransaction();
    transaction.getTransactionActivity().tracerStarted(new OtherRootTracer(transaction, signature, this, new SimpleMetricNameFormat("test")));
    TracingMethodTracerFactory mtf = new TracingMethodTracerFactory();
    CustomTracerFactory factory = new CustomTracerFactory(mtf);
    Tracer tracer = factory.getTracer(transaction, signature, this, new Object[0]);
    Assert.assertFalse(tracer instanceof TransactionActivityInitiator);
    Assert.assertNotNull(mtf.tracer);
    Exception ex = new Exception();
    tracer.finish(ex);
    Assert.assertEquals(ex, mtf.tracer.exception);
}
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 23 with SimpleMetricNameFormat

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

the class TransactionNamingTest method startOtherTransaction.

private void startOtherTransaction(String uri) throws Exception {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("", "", "");
    MetricNameFormat format = new SimpleMetricNameFormat(uri);
    Tracer tracer = new OtherRootTracer(tx, sig, this, format);
    tx.getTransactionActivity().tracerStarted(tracer);
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 24 with SimpleMetricNameFormat

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

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

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