use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat in project newrelic-java-agent by newrelic.
the class MetricNameFormatTest method classMethodMetricNameFormat.
@Test
public void classMethodMetricNameFormat() {
ClassMethodSignature sig = new ClassMethodSignature("com.foo.Bar", "getName()", "()V");
Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", ClassMethodMetricNameFormat.getMetricName(sig, this));
Assert.assertEquals("Test/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", ClassMethodMetricNameFormat.getMetricName(sig, this, "Test"));
ClassMethodMetricNameFormat formatter = new ClassMethodMetricNameFormat(sig, this.getClass().getName());
Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getMetricName());
Assert.assertEquals("Java/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", formatter.getTransactionSegmentName());
Assert.assertEquals("Spring/com.newrelic.agent.tracers.nameformatters.MetricNameFormatTest/getName()", new ClassMethodMetricNameFormat(sig, this.getClass().getName(), "Spring").getMetricName());
}
use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat in project newrelic-java-agent by newrelic.
the class JsonTracer method generateDefaultTracer.
private DefaultTracer generateDefaultTracer(long txaStartTime) {
ClassMethodSignature sig = new ClassMethodSignature("clazz", tracerName, "()");
Object reference = new Object();
DefaultTracer tracer = new DefaultTracer(Transaction.getTransaction().getTransactionActivity(), sig, reference, new ClassMethodMetricNameFormat(sig, reference), txaStartTime + startTimeNs);
Transaction.getTransaction().getTransactionActivity().tracerStarted(tracer);
return tracer;
}
use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat in project newrelic-java-agent by newrelic.
the class CustomTracerFactory method doGetTracer.
@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, Object object, Object[] args) {
Tracer parent = transaction.getTransactionActivity().getLastTracer();
final MethodTracer methodTracer = tracerFactory.methodInvoked(sig.getMethodName(), object, args);
// no custom method tracer, just hook up a normal tracer
if (methodTracer == null) {
return parent == null ? new OtherRootTracer(transaction, sig, object, new ClassMethodMetricNameFormat(sig, object)) : new DefaultTracer(transaction, sig, object);
} else // otherwise we have to let the method tracer know when the method exits
{
// DefaultTracer. This is the safest way to implement this for now.
if (parent == null) {
return new OtherRootTracer(transaction, sig, object, new ClassMethodMetricNameFormat(sig, object)) {
@Override
protected void doFinish(Throwable throwable) {
super.doFinish(throwable);
methodTracer.methodFinishedWithException(throwable);
}
@Override
protected void doFinish(int opcode, Object returnValue) {
super.doFinish(opcode, returnValue);
methodTracer.methodFinished(returnValue);
}
};
} else {
return new DefaultTracer(transaction, sig, object) {
@Override
protected void doFinish(Throwable throwable) {
super.doFinish(throwable);
methodTracer.methodFinishedWithException(throwable);
}
@Override
protected void doFinish(int opcode, Object returnValue) {
super.doFinish(opcode, returnValue);
methodTracer.methodFinished(returnValue);
}
};
}
}
}
use of com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat 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.ClassMethodMetricNameFormat in project newrelic-java-agent by newrelic.
the class CXFPointCut method doGetTracer.
@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, final Object servletDest, Object[] args) {
try {
Object endpointInfo = servletDest.getClass().getMethod("getEndpointInfo").invoke(servletDest);
Object address = endpointInfo.getClass().getMethod("getAddress").invoke(endpointInfo);
transaction.getInternalParameters().put(CXF_ENDPOINT_ADDRESS_PARAMETER_NAME, address);
} catch (Throwable t) {
Agent.LOG.log(Level.FINER, "Error parsing CXF transaction", t);
}
return new DefaultTracer(transaction, sig, servletDest, new ClassMethodMetricNameFormat(sig, servletDest));
}
Aggregations