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));
}
}
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())));
}
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;
}
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();
}
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();
}
Aggregations