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