use of com.newrelic.agent.tracers.DefaultTracer 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.DefaultTracer 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.DefaultTracer 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.DefaultTracer 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;
}
};
}
use of com.newrelic.agent.tracers.DefaultTracer 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));
}
}
Aggregations