use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class ExternalTracerTest method testExternalTracerExcludeUri.
@Test
public void testExternalTracerExcludeUri() throws Exception {
before("/com/newrelic/agent/config/exclude_request_uri.yml");
DefaultTracer tracer = prepareTracer();
TransactionTracerConfig ttConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getTransactionTracerConfig();
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
TransactionSegment segment = tracer.getTransactionSegment(ttConfig, sqlObfuscator, 0, null);
TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
String uri = "http://myhost:1234/Parameters";
String queryParams = "?data=confidential";
tracer.reportAsExternal(GenericParameters.library("MyLibrary").uri(URI.create(uri + queryParams)).procedure("other").build());
tracer.recordMetrics(stats);
String segmentUri = segment.getUri();
tracer.finish(Opcodes.RETURN, null);
Assert.assertEquals(null, segmentUri);
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class ExternalTracerTest method testExternalTracerIncludeUri.
@Test
public void testExternalTracerIncludeUri() throws Exception {
before("/com/newrelic/agent/config/span_events.yml");
DefaultTracer tracer = prepareTracer();
TransactionTracerConfig ttConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getTransactionTracerConfig();
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
TransactionSegment segment = tracer.getTransactionSegment(ttConfig, sqlObfuscator, 0, null);
TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
String uri = "http://myhost:1234/Parameters";
String queryParams = "?data=confidential";
tracer.reportAsExternal(GenericParameters.library("MyLibrary").uri(URI.create(uri + queryParams)).procedure("other").build());
tracer.recordMetrics(stats);
String segmentUri = segment.getUri();
tracer.finish(Opcodes.RETURN, null);
Assert.assertNotNull(segmentUri);
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsBadValue.
@Test
public void requestXStartHeaderRecordMetricsBadValue() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "server1 t=cafebabe");
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
TransactionStats statsEngine = new TransactionStats();
dispatcher.recordHeaderMetrics(statsEngine);
Assert.assertEquals(0, statsEngine.getSize());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DistributedTraceServiceImplTest method txnFinishedInboundPayload.
@Test
public void txnFinishedInboundPayload() {
Map<String, Object> connectInfo = new HashMap<>();
connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "1acct234");
connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "67890");
AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
distributedTraceService.connected(null, agentConfig);
TransactionStats transactionStats = new TransactionStats();
Map<String, Object> intrinsicAttributes = new HashMap<>();
long payloadSendTimestamp = 1002000;
long startTimeInMillis = 1005000;
long responseTimeInNanos = TimeUnit.MILLISECONDS.toNanos(1350);
String json = new DistributedTracePayloadBuilder().setTimestamp(payloadSendTimestamp).setHost("datanerd.us.com").setParentType("Browser").setAccountId("123456").setTrustKey("67890").setApplicationId("6789").setTransactionId("badcafe3").setTripId("cattrip").setPriority(0.0f).setDepth(0).setSyntheticsJob(null).setSyntheticsMonitor(null).setSyntheticsResource(null).createJsonPayload();
DistributedTracePayloadImpl payload = new DistributedTracePayloadParser(NewRelic.getAgent().getMetricAggregator(), distributedTraceService, Agent.LOG).parse(null, json);
TransactionData transactionData = createTransactionData(intrinsicAttributes, startTimeInMillis, responseTimeInNanos, payload);
distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
SimpleStatsEngine unscopedStats = transactionStats.getUnscopedStats();
assertEquals(1.35f, unscopedStats.getOrCreateResponseTimeStats("DurationByCaller/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
assertEquals(3.0f, unscopedStats.getOrCreateResponseTimeStats("TransportDuration/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
}
use of com.newrelic.agent.stats.TransactionStats 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());
}
Aggregations