Search in sources :

Example 1 with TransactionNamingPolicy

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);
}
Also used : TransactionNamingPolicy(com.newrelic.agent.transaction.TransactionNamingPolicy)

Example 2 with TransactionNamingPolicy

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;
    }
}
Also used : TransactionNamingPolicy(com.newrelic.agent.transaction.TransactionNamingPolicy)

Example 3 with TransactionNamingPolicy

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());
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) TransactionNamingPolicy(com.newrelic.agent.transaction.TransactionNamingPolicy) Test(org.junit.Test)

Example 4 with TransactionNamingPolicy

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;
        }
    };
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Transaction(com.newrelic.agent.Transaction) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) TransactionNamingPolicy(com.newrelic.agent.transaction.TransactionNamingPolicy) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with TransactionNamingPolicy

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);
}
Also used : TransactionNamingPolicy(com.newrelic.agent.transaction.TransactionNamingPolicy)

Aggregations

TransactionNamingPolicy (com.newrelic.agent.transaction.TransactionNamingPolicy)9 Transaction (com.newrelic.agent.Transaction)3 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Test (org.junit.Test)1