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();
}
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");
}
}
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");
}
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());
}
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);
}
Aggregations