Search in sources :

Example 26 with SimpleMetricNameFormat

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

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

the class CXFInvokerPointCut method doGetTracer.

@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, Object invoker, Object[] args) {
    Object service = args[1];
    Method method = (Method) args[2];
    String address = (String) transaction.getInternalParameters().remove(CXFPointCut.CXF_ENDPOINT_ADDRESS_PARAMETER_NAME);
    if (address != null) {
        StringBuilder path = new StringBuilder(address);
        if (!address.endsWith("/")) {
            path.append('/');
        }
        path.append(method.getName());
        setTransactionName(transaction, getCXFRequestUri(address, method));
    } else {
        Agent.LOG.log(Level.FINEST, "The CXF endpoint address is null.");
        String txnName = buildCXFTransactionName(service.getClass().getName(), method.getName());
        setTransactionName(transaction, txnName);
    }
    return new DefaultTracer(transaction, sig, invoker, new SimpleMetricNameFormat(Strings.join('/', MetricNames.JAVA, service.getClass().getName(), method.getName())));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Method(java.lang.reflect.Method) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 28 with SimpleMetricNameFormat

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

the class JasperCompilerPointCut method doGetTracer.

@Override
public Tracer doGetTracer(Transaction tx, ClassMethodSignature sig, Object compiler, Object[] args) {
    Tracer parent = tx.getTransactionActivity().getLastTracer();
    if (parent != null && parent instanceof JasperCompilerTracer) {
        // this is JSP 2.0 and both instrumented "compile" methods are on the stack
        return null;
    }
    try {
        Object context = compiler.getClass().getMethod("getCompilationContext").invoke(compiler);
        if (context != null) {
            String page = (String) context.getClass().getMethod("getJspFile").invoke(context);
            if (page != null) {
                String msg = MessageFormat.format("Compiling JSP: {0}", page);
                Agent.LOG.fine(msg);
                /*
                     * Track the current JSP file being compiled.
                     * 
                     * @see com.newrelic.agent.tracers.jasper.GeneratorVisitTracerFactory
                     */
                GeneratorVisitTracerFactory.noticeJspCompile(tx, page);
                JasperCompilerTracer tracer = new JasperCompilerTracer(tx, sig, compiler, new SimpleMetricNameFormat("View" + page.replace('.', '_') + "/Compile"));
                return tracer;
            }
        }
    } catch (Throwable t) {
        Agent.LOG.severe("Unable to generate a Jasper compilation metric: " + t.getMessage());
    }
    return null;
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 29 with SimpleMetricNameFormat

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

the class DatabaseServiceTest method instanceLocalhostReplace.

@Test
public void instanceLocalhostReplace() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    Map<String, Object> dsConfigMap = createMap();
    dsConfigMap.put(DatastoreConfigImpl.INSTANCE_REPORTING, true);
    configMap.put(AgentConfigImpl.DATASTORE_TRACER, dsConfigMap);
    createServiceManager(configMap);
    final Connection connection = Mockito.mock(Connection.class);
    DatastoreInstanceDetection.detectConnectionAddress();
    DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("localhost", 8080));
    DatastoreInstanceDetection.stopDetectingConnectionAddress();
    Transaction transaction = Transaction.getTransaction(true);
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    TestDefaultSqlTracer tracer = new TestDefaultSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
    tracer.setRawSql("select * from metrics");
    AgentHelper.setLastTracer(tracer);
    tracer.provideConnection(connection);
    ConnectionFactory connectionFactory = createConnectionFactory(connection);
    tracer.setConnectionFactory(connectionFactory);
    tracer.finish(Opcodes.ARETURN, new DummyResultSet());
    String notExpectedRollupMetricName = getScopedInstanceDBMetric(DatastoreVendor.MySQL.name(), "localhost", "8080");
    Assert.assertFalse(tracer.getRolledUpMetricNamesForTesting().contains(notExpectedRollupMetricName));
    String expectedRollupMetricName = getScopedInstanceDBMetric(DatastoreVendor.MySQL.name(), DatastoreMetrics.HOSTNAME, "8080");
    Assert.assertTrue(String.format("Expected instance metric %s found", expectedRollupMetricName), tracer.getRolledUpMetricNamesForTesting().contains(expectedRollupMetricName));
    Transaction.clearTransaction();
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) InetSocketAddress(java.net.InetSocketAddress) Connection(java.sql.Connection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

Example 30 with SimpleMetricNameFormat

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

the class DatabaseServiceTest method instanceDisabled.

@Test
public void instanceDisabled() throws Exception {
    Map<String, Object> configMap = createStagingMap();
    Map<String, Object> dbConfigMap = createMap();
    Map<String, Object> nestedMap = new HashMap<>();
    nestedMap.put(DatastoreConfigImpl.ENABLED, !DatastoreConfigImpl.INSTANCE_REPORTING_DEFAULT_ENABLED);
    dbConfigMap.put(DatastoreConfigImpl.INSTANCE_REPORTING, nestedMap);
    configMap.put(AgentConfigImpl.DATASTORE_TRACER, dbConfigMap);
    createServiceManager(configMap);
    final Connection connection = Mockito.mock(Connection.class);
    Transaction transaction = Transaction.getTransaction(true);
    ClassMethodSignature sig = new ClassMethodSignature("com.foo.Statement", "executeQuery", "(Ljava/lang/String;)Ljava/sql/ResultSet;");
    TestDefaultSqlTracer tracer = new TestDefaultSqlTracer(transaction, sig, null, new SimpleMetricNameFormat(null), DefaultTracer.DEFAULT_TRACER_FLAGS);
    ConnectionFactory connectionFactory = createConnectionFactory(connection);
    tracer.setConnectionFactory(connectionFactory);
    tracer.setRawSql("select * from metrics");
    tracer.provideConnection(connection);
    AgentHelper.setLastTracer(tracer);
    tracer.finish(Opcodes.ARETURN, new DummyResultSet());
    String expectedRollupMetricName = getScopedInstanceDBMetric(DatastoreVendor.MySQL.name(), "unknown", "unknown");
    Assert.assertFalse(tracer.getRolledUpMetricNamesForTesting().contains(expectedRollupMetricName));
    Transaction.clearTransaction();
}
Also used : ConnectionFactory(com.newrelic.agent.bridge.datastore.ConnectionFactory) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) HashMap(java.util.HashMap) Connection(java.sql.Connection) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

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