use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method referrerHeaderRecorded2.
@Test
public void referrerHeaderRecorded2() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setHeader("Referer", "http://example.com:80?myparam=test&secret=donttell");
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
Transaction tx = Transaction.getTransaction();
dispatcher.setStatus(500);
dispatcher.transactionActivityWithResponseFinished();
Assert.assertTrue("Referer header should be captured", ((String) tx.getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME)).contains("example.com"));
Assert.assertFalse("Referer header shouldn't include url parameters", ((String) tx.getAgentAttributes().get(AttributeNames.REQUEST_REFERER_PARAMETER_NAME)).contains("donttell"));
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method statusCodeMetric.
@Test
public void statusCodeMetric() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
Transaction tx = Transaction.getTransaction();
dispatcher.setStatus(200);
dispatcher.freezeStatus();
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
Assert.assertEquals(200, dispatcher.getStatus());
Assert.assertEquals(200, tx.getStatus());
String expected = "Network/Inbound/StatusCode/200";
Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats(expected).getCallCount());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXQueueStartHeaderRecordMetrics.
@Test
public void requestXQueueStartHeaderRecordMetrics() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long queueStartTimeInMicroseconds = nowInMicroseconds - 10000;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=" + queueStartTimeInMicroseconds);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
TransactionStats statsEngine = new TransactionStats();
dispatcher.recordHeaderMetrics(statsEngine);
String spec = MetricName.QUEUE_TIME.getName();
long txStartTimeInMicroseconds = TimeUnit.MICROSECONDS.convert(dispatcher.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
float expectedQueueTime = (float) (txStartTimeInMicroseconds - queueStartTimeInMicroseconds) / TimeConversion.MICROSECONDS_PER_SECOND;
Assert.assertEquals(1, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
assertDelta(expectedQueueTime, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .001);
Assert.assertEquals(1, statsEngine.getUnscopedStats().getStatsMap().size());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXQueueStartHeaderBadValue.
@Test
public void requestXQueueStartHeaderBadValue() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_QUEUE_START_HEADER, "t=cafebabe");
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
Assert.assertEquals(0, dispatcher.getQueueTime());
}
use of com.newrelic.agent.dispatchers.WebRequestDispatcher in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsMultipleServers.
@Test
public void requestXStartHeaderRecordMetricsMultipleServers() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long requestStartTimeInMicroseconds1 = nowInMicroseconds - 30000;
long requestStartTimeInMicroseconds2 = nowInMicroseconds - 20000;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=" + requestStartTimeInMicroseconds1 + "server2 t=" + requestStartTimeInMicroseconds2);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
long txStartTimeInMicroseconds = TimeUnit.MICROSECONDS.convert(dispatcher.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
float expected1 = (float) (requestStartTimeInMicroseconds2 - requestStartTimeInMicroseconds1) / TimeConversion.MICROSECONDS_PER_SECOND;
float expected2 = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds2) / TimeConversion.MICROSECONDS_PER_SECOND;
float expectedTotal = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds1) / TimeConversion.MICROSECONDS_PER_SECOND;
TransactionStats statsEngine = new TransactionStats();
dispatcher.recordHeaderMetrics(statsEngine);
String spec = MetricName.QUEUE_TIME.getName();
Assert.assertEquals(1, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getCallCount());
assertDelta(expectedTotal, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .001);
Assert.assertEquals(1, statsEngine.getSize());
}
Aggregations