use of com.newrelic.agent.transaction.TransactionNamingPolicy in project newrelic-java-agent by newrelic.
the class Transaction method doSetTransactionName.
private boolean doSetTransactionName(TransactionNamePriority namePriority, boolean override, String category, String... parts) {
if (TransactionNamingUtility.isLessThan(namePriority, TransactionNamePriority.CUSTOM_HIGH, getNamingScheme()) && !isTransactionNamingEnabled()) {
return false;
}
String name = Strings.join('/', parts);
if (dispatcher == null) {
if (Agent.LOG.isFinestEnabled()) {
Agent.LOG.finest(MessageFormat.format("Unable to set the transaction name to \"{0}\" - no transaction", name));
}
return false;
}
TransactionNamingPolicy policy = override ? TransactionNamingPolicy.getSameOrHigherPriorityTransactionNamingPolicy() : TransactionNamingPolicy.getHigherPriorityTransactionNamingPolicy();
return policy.setTransactionName(this, name, category, namePriority);
}
use of com.newrelic.agent.transaction.TransactionNamingPolicy in project newrelic-java-agent by newrelic.
the class Transaction method setNormalizedUri.
/**
* Use NewRelic#setTransactionName(String, String)
*/
@Deprecated
public void setNormalizedUri(String normalizedUri) {
synchronized (lock) {
if (normalizedUri == null || normalizedUri.length() == 0) {
return;
}
TransactionNamingPolicy policy = TransactionNamingPolicy.getSameOrHigherPriorityTransactionNamingPolicy();
if (Agent.LOG.isLoggable(Level.FINER)) {
if (policy.canSetTransactionName(this, TransactionNamePriority.CUSTOM_HIGH)) {
String msg = MessageFormat.format("Setting transaction name to normalized URI \"{0}\" for transaction {1}", normalizedUri, this);
Agent.LOG.finer(msg);
}
}
policy.setTransactionName(this, normalizedUri, MetricNames.NORMALIZED_URI, TransactionNamePriority.CUSTOM_HIGH);
this.normalizedUri = normalizedUri;
}
}
use of com.newrelic.agent.transaction.TransactionNamingPolicy in project newrelic-java-agent by newrelic.
the class TransactionNamingTest method transactionNameAlreadySet.
@Test
public void transactionNameAlreadySet() throws Exception {
startWebTransaction("/dude/test/man");
String normalizedUri = "/dude2/test2/man2";
Transaction tx = Transaction.getTransaction();
TransactionNamingPolicy policy = TransactionNamingPolicy.getSameOrHigherPriorityTransactionNamingPolicy();
policy.setTransactionName(tx, normalizedUri, null, TransactionNamePriority.CUSTOM_HIGH);
PriorityTransactionName ptn = tx.getPriorityTransactionName();
tx.getDispatcher().setTransactionName();
Assert.assertEquals(ptn, tx.getPriorityTransactionName());
}
use of com.newrelic.agent.transaction.TransactionNamingPolicy 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.transaction.TransactionNamingPolicy in project newrelic-java-agent by newrelic.
the class CXFInvokerPointCut method setTransactionName.
private void setTransactionName(Transaction transaction, String path) {
if (!transaction.isTransactionNamingEnabled()) {
return;
}
TransactionNamingPolicy policy = TransactionNamingPolicy.getHigherPriorityTransactionNamingPolicy();
if (Agent.LOG.isLoggable(Level.FINER)) {
if (policy.canSetTransactionName(transaction, TransactionNamePriority.FRAMEWORK)) {
String msg = MessageFormat.format("Setting transaction name to \"{0}\" using CXF", path);
Agent.LOG.finer(msg);
}
}
policy.setTransactionName(transaction, path, CXF, TransactionNamePriority.FRAMEWORK);
}
Aggregations