Search in sources :

Example 11 with Dispatcher

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

the class AgentTest method testSupportabilityMetrics.

@Test
public void testSupportabilityMetrics() {
    String requestInitializedSupportabilityMetric = "Supportability/Transaction/RequestInitialized";
    String requestDestroyedSupportabilityMetric = "Supportability/Transaction/RequestDestroyed";
    String classloaderTimeSupportabilityMetric = "Supportability/Classloader/TransformTime";
    AgentConfig agentConfig = AgentHelper.mockAgentConfig();
    Assert.assertNotNull(agentConfig);
    // final HttpServletRequest httpRequest = Mockito.mock(HttpServletRequest.class);
    final com.newrelic.api.agent.Request request = Mockito.mock(com.newrelic.api.agent.Request.class);
    Mockito.when(request.getHeaderType()).thenReturn(HeaderType.HTTP);
    // final HttpServletResponse httpResponse = Mockito.mock(HttpServletResponse.class);
    final com.newrelic.api.agent.Response response = Mockito.mock(com.newrelic.api.agent.Response.class);
    // Assert that the dispatcher starts null, gets initialized, and then doesn't change.
    Transaction tx = Transaction.getTransaction();
    Assert.assertNull(tx.getDispatcher());
    tx.requestInitialized(request, response);
    Dispatcher disp = tx.getDispatcher();
    Assert.assertNotNull(disp);
    tx.requestInitialized(request, response);
    Assert.assertEquals(disp, tx.getDispatcher());
    tx.requestDestroyed();
    Map<String, Integer> metricData = InstrumentTestUtils.getAndClearMetricData();
    Assert.assertNotNull("requestInitialized Supportability Metric", metricData.get(requestInitializedSupportabilityMetric));
    Assert.assertNotNull("requestDestroyed Supportability Metric", metricData.get(requestDestroyedSupportabilityMetric));
    Assert.assertNotNull("classloaderTime Supportability Metric", metricData.get(classloaderTimeSupportabilityMetric));
    // There's no obvious way to tell that the transaction complete, so the test just
    // checks that we don't throw an exception here:
    tx.requestDestroyed();
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) NewRelicIgnoreTransaction(test.newrelic.test.agent.TraceAnnotationTest.NewRelicIgnoreTransaction) Transaction(com.newrelic.agent.Transaction) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 12 with Dispatcher

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

the class NewRelicApiImplementation method setProductName.

/**
 * Set the product name to associate with the RUM JavaScript footer for the current web transaction.
 */
@Override
public void setProductName(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 product name to \"{0}\" in NewRelic API - no transaction", name));
            return;
        }
        if (!dispatcher.isWebTransaction()) {
            Agent.LOG.finer(MessageFormat.format("Unable to set the product 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 product name to \"{0}\" in NewRelic API", name);
            Agent.LOG.finer(msg);
        }
        MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SET_PRODUCT_NAME);
        attributeSender.addAttribute("product", name, "setProductName");
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher)

Example 13 with Dispatcher

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

the class NewRelicApiImplementation method setUserName.

/**
 * Set the user name to associate with the RUM JavaScript footer for the current web transaction.
 */
@Override
public void setUserName(String name) {
    Transaction tx = Transaction.getTransaction(false);
    if (tx == null) {
        return;
    }
    Dispatcher dispatcher = tx.getDispatcher();
    if (dispatcher == null) {
        Agent.LOG.finer(MessageFormat.format("Unable to set the user name to \"{0}\" in NewRelic API - no transaction", name));
        return;
    }
    if (!dispatcher.isWebTransaction()) {
        Agent.LOG.finer(MessageFormat.format("Unable to set the user 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 user name to \"{0}\" in NewRelic API", name);
        Agent.LOG.finer(msg);
    }
    MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SET_USER_NAME);
    attributeSender.addAttribute("user", name, "setUserName");
}
Also used : Transaction(com.newrelic.agent.Transaction) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher)

Example 14 with Dispatcher

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

the class TransactionDispatcherTest method testSetDispatcherFirstWins.

@Test
public void testSetDispatcherFirstWins() {
    Transaction tx = Transaction.getTransaction(true);
    Dispatcher dispatcherOne = new WebRequestDispatcher(new MockHttpRequest(), new MockHttpResponse(), tx);
    tx.setDispatcher(dispatcherOne);
    assertEquals(dispatcherOne, tx.getDispatcher());
    Dispatcher dispatcherTwo = new WebRequestDispatcher(new MockHttpRequest(), new MockHttpResponse(), tx);
    tx.setDispatcher(dispatcherTwo);
    assertEquals(dispatcherOne, tx.getDispatcher());
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Test(org.junit.Test)

Example 15 with Dispatcher

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

the class TransactionDataTest method isWebTransaction.

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

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