Search in sources :

Example 16 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class TransactionDataTest method getDispatcher.

@Test
public void getDispatcher() {
    Dispatcher expected = Mockito.mock(Dispatcher.class);
    Mockito.when(tx.getDispatcher()).thenReturn(expected);
    TransactionData txd = getTxData(tx);
    Dispatcher result = txd.getDispatcher();
    Assert.assertSame(expected, result);
}
Also used : Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) Test(org.junit.Test)

Example 17 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class IgnoreApdexInvocationHandler method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Transaction transaction = Transaction.getTransaction(false);
    if (transaction != null) {
        Dispatcher dispatcher = transaction.getDispatcher();
        if (dispatcher != null) {
            dispatcher.setIgnoreApdex(true);
            if (Agent.LOG.isLoggable(Level.FINER)) {
                String msg = MessageFormat.format("Set Ignore apdex to \"{0}\"", true);
                Agent.LOG.log(Level.FINER, msg, new Exception());
            }
        }
    }
    return null;
}
Also used : Transaction(com.newrelic.agent.Transaction) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher)

Example 18 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class NewRelicApiImplementation method setTransactionName.

/**
 * Set the name of the current transaction.
 *
 * @param category
 * @param name     The name of the transaction in URI format. example: /store/order
 */
@Override
public void setTransactionName(String category, String name) {
    if (StringUtils.isEmpty(category)) {
        category = MetricNames.CUSTOM;
    }
    if (name == null || name.length() == 0) {
        Agent.LOG.log(Level.FINER, "Unable to set the transaction name to an empty string");
        return;
    }
    if (!name.startsWith("/")) {
        name = "/" + name;
    }
    Transaction tx = Transaction.getTransaction(false);
    if (tx == null) {
        return;
    }
    Dispatcher dispatcher = tx.getDispatcher();
    if (dispatcher == null) {
        if (Agent.LOG.isFinerEnabled()) {
            Agent.LOG.finer(MessageFormat.format("Unable to set the transaction name to \"{0}\" in NewRelic API - no transaction", name));
        }
        return;
    }
    boolean isWebTransaction = dispatcher.isWebTransaction();
    TransactionNamingPolicy policy = TransactionNamingPolicy.getSameOrHigherPriorityTransactionNamingPolicy();
    com.newrelic.agent.bridge.TransactionNamePriority namePriority = MetricNames.URI.equals(category) ? com.newrelic.agent.bridge.TransactionNamePriority.REQUEST_URI : com.newrelic.agent.bridge.TransactionNamePriority.CUSTOM_HIGH;
    if (Agent.LOG.isLoggable(Level.FINER)) {
        if (policy.canSetTransactionName(tx, namePriority)) {
            String msg = MessageFormat.format("Setting {1} transaction name to \"{0}\" in NewRelic API", name, isWebTransaction ? "web" : "background");
            Agent.LOG.finer(msg);
        } else {
            Agent.LOG.finer("Unable to set the transaction name to " + name);
        }
    }
    synchronized (tx) {
        policy.setTransactionName(tx, name, category, namePriority);
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) TransactionNamingPolicy(com.newrelic.agent.transaction.TransactionNamingPolicy)

Example 19 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class NewRelicApiImplementation method setAccountName.

/**
 * Set the account name to associate with the RUM JavaScript footer for the current web transaction.
 */
@Override
public void setAccountName(String name) {
    Transaction tx = Transaction.getTransaction(false);
    if (tx != null) {
        Dispatcher dispatcher = tx.getDispatcher();
        if (dispatcher == null) {
            Agent.LOG.finer(MessageFormat.format("Unable to set the account name to \"{0}\" in NewRelic API - no transaction", name));
            return;
        }
        if (!dispatcher.isWebTransaction()) {
            Agent.LOG.finer(MessageFormat.format("Unable to set the account name to \"{0}\" in NewRelic API - transaction is not a web transaction", name));
            return;
        }
        if (Agent.LOG.isLoggable(Level.FINER)) {
            String msg = MessageFormat.format("Attempting to set account name to \"{0}\" in NewRelic API", name);
            Agent.LOG.finer(msg);
        }
        attributeSender.addAttribute("account", name, "setAccountName");
        MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SET_ACCOUNT_NAME);
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher)

Example 20 with Dispatcher

use of com.newrelic.agent.dispatchers.Dispatcher in project newrelic-java-agent by newrelic.

the class DistributedTraceServiceImplTest method createTransactionData.

private TransactionData createTransactionData(Map<String, Object> intrinsicAttributes, long startTimeInMillis, long responseTimeInNanos, DistributedTracePayloadImpl payload) {
    long payloadTimestamp = payload != null ? payload.timestamp : 0;
    Transaction tx = Mockito.mock(Transaction.class);
    SpanProxy spanProxy = new SpanProxy();
    spanProxy.acceptDistributedTracePayload(payload);
    CrossProcessTransactionState crossProcessTransactionState = Mockito.mock(CrossProcessTransactionState.class);
    Dispatcher dispatcher = Mockito.mock(Dispatcher.class);
    TransactionTimer timer = Mockito.mock(TransactionTimer.class);
    when(tx.getIntrinsicAttributes()).thenReturn(intrinsicAttributes);
    when(tx.getSpanProxy()).thenReturn(spanProxy);
    when(crossProcessTransactionState.getTripId()).thenReturn("abc123");
    when(tx.getCrossProcessTransactionState()).thenReturn(crossProcessTransactionState);
    when(dispatcher.isWebTransaction()).thenReturn(true);
    when(tx.getDispatcher()).thenReturn(dispatcher);
    when((tx.getTransportDurationInMillis())).thenReturn(startTimeInMillis - payloadTimestamp);
    when(timer.getResponseTimeInNanos()).thenReturn(responseTimeInNanos);
    when(tx.getTransactionTimer()).thenReturn(timer);
    when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
    when(tx.getTransportType()).thenReturn(TransportType.HTTPS);
    return new TransactionData(tx, 0);
}
Also used : Transaction(com.newrelic.agent.Transaction) CrossProcessTransactionState(com.newrelic.agent.CrossProcessTransactionState) TransactionData(com.newrelic.agent.TransactionData) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer)

Aggregations

Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)20 Transaction (com.newrelic.agent.Transaction)11 Test (org.junit.Test)9 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)4 AgentConfig (com.newrelic.agent.config.AgentConfig)2 Tracer (com.newrelic.agent.tracers.Tracer)2 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)2 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)2 TransactionTimer (com.newrelic.agent.transaction.TransactionTimer)2 InboundHeaders (com.newrelic.api.agent.InboundHeaders)2 NewRelicIgnoreTransaction (test.newrelic.test.agent.TraceAnnotationTest.NewRelicIgnoreTransaction)2 CrossProcessTransactionState (com.newrelic.agent.CrossProcessTransactionState)1 TransactionData (com.newrelic.agent.TransactionData)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)1 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 SpanProxy (com.newrelic.agent.tracing.SpanProxy)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1 TransactionNamingPolicy (com.newrelic.agent.transaction.TransactionNamingPolicy)1