Search in sources :

Example 21 with TransactionStats

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);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionStats(com.newrelic.agent.stats.TransactionStats) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) Test(org.junit.Test)

Example 22 with TransactionStats

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);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionStats(com.newrelic.agent.stats.TransactionStats) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) Test(org.junit.Test)

Example 23 with TransactionStats

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Example 24 with TransactionStats

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);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) TransactionStats(com.newrelic.agent.stats.TransactionStats) DistributedTracePayloadBuilder(com.newrelic.agent.DistributedTracePayloadBuilder) HashMap(java.util.HashMap) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 25 with TransactionStats

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Test(org.junit.Test)

Aggregations

TransactionStats (com.newrelic.agent.stats.TransactionStats)104 Test (org.junit.Test)90 TransactionData (com.newrelic.agent.TransactionData)40 EventTestHelper.generateTransactionData (com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData)15 Tracer (com.newrelic.agent.tracers.Tracer)15 HashMap (java.util.HashMap)14 SpanEvent (com.newrelic.agent.model.SpanEvent)13 TransactionService (com.newrelic.agent.TransactionService)12 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)11 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)11 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)11 ArrayList (java.util.ArrayList)11 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)10 Map (java.util.Map)9 Transaction (com.newrelic.agent.Transaction)8 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)8 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)7 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 JSONArray (org.json.simple.JSONArray)5