Search in sources :

Example 46 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class CrossProcessTransactionStateImplTest method testAppDataHeader.

@Test
public void testAppDataHeader() {
    String encodingKey = "test";
    String incomingId = "1#23";
    String txGuid = "5001D";
    String obfuscatedAppData = Obfuscator.obfuscateNameUsingKey("[\"6#66\",\"WebTransaction\\/test\\/test\",1.0,0.2,12345,\"" + txGuid + "\",false]", encodingKey);
    ExtendedRequest request = createRequestFromStandardHeaders(Obfuscator.obfuscateNameUsingKey(incomingId, encodingKey), null, "12345");
    stats = new TransactionStats();
    configureTestMocks(encodingKey, txGuid, obfuscatedAppData, request);
    CrossProcessTransactionStateImpl crossProcessTransactionState = CrossProcessTransactionStateImpl.create(tx);
    crossProcessTransactionState.writeResponseHeaders();
    crossProcessTransactionState.writeResponseHeaders();
    verifyMocks(obfuscatedAppData);
    assertEquals(1, stats.getUnscopedStats().getSize());
    ResponseTimeStats clientAppStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("ClientApplication/" + incomingId + "/all");
    assertEquals(1, clientAppStats.getCallCount());
    assertEquals(incomingId, tx.getInboundHeaderState().getClientCrossProcessId());
    assertNull(tx.getInboundHeaderState().getReferrerGuid());
}
Also used : ResponseTimeStats(com.newrelic.agent.stats.ResponseTimeStats) TransactionStats(com.newrelic.agent.stats.TransactionStats) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 47 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class DataCollectionConfigCrossAgentTest method createAndVerifyTransactionTrace.

private void createAndVerifyTransactionTrace(Long expectedCount, Long expectedEndpointCount) {
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    long eventsToCreate = 1;
    if (expectedCount > 1) {
        eventsToCreate = expectedCount;
    }
    for (long i = 0; i < eventsToCreate; i++) {
        TransactionData transactionData = EventTestHelper.generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME, 10000);
        TransactionStats transactionStats = new TransactionStats();
        transactionTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
    }
    // Verify that we sent (or didn't send) the appropriate traces
    StatsEngine statsEngine = new StatsEngineImpl();
    transactionTraceService.beforeHarvest(APP_NAME, statsEngine);
    transactionTraceService.afterHarvest(APP_NAME);
    int transactionTracesSeen = rpmService.getTransactionTracesSeen();
    assertEquals(expectedEndpointCount.intValue(), transactionTracesSeen);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) StatsEngine(com.newrelic.agent.stats.StatsEngine)

Example 48 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class DistributedTraceCrossAgentTest method runTest.

@Test
public void runTest() throws ParseException, IOException {
    String accountKey = (String) jsonTest.get("trusted_account_key");
    String accountId = (String) jsonTest.get("account_id");
    String transportType = (String) jsonTest.get("transport_type");
    Boolean webTransaction = (Boolean) jsonTest.get("web_transaction");
    Boolean raisesException = (Boolean) jsonTest.get("raises_exception");
    Boolean forceSampledTrue = (Boolean) jsonTest.get("force_sampled_true");
    Long majorVersion = (Long) jsonTest.get("major_version");
    Long minorVersion = (Long) jsonTest.get("minor_version");
    Boolean spanEventsEnabled = (Boolean) jsonTest.get("span_events_enabled");
    replaceConfig(spanEventsEnabled);
    Assert.assertEquals(majorVersion.intValue(), ServiceFactory.getDistributedTraceService().getMajorSupportedCatVersion());
    Assert.assertEquals(minorVersion.intValue(), ServiceFactory.getDistributedTraceService().getMinorSupportedCatVersion());
    JSONArray outbound_payloads = (JSONArray) jsonTest.get("outbound_payloads");
    JSONArray inbound_payloads = (JSONArray) jsonTest.get("inbound_payloads");
    ArrayList expectedMetrics = (ArrayList) jsonTest.get("expected_metrics");
    Map<String, Object> intrinsics = (Map<String, Object>) jsonTest.get("intrinsics");
    Map<String, Object> commonAssertions = (Map<String, Object>) intrinsics.get("common");
    ArrayList targetEvents = (ArrayList) intrinsics.get("target_events");
    Map<String, Object> transactionAssertions = (Map<String, Object>) intrinsics.get("Transaction");
    Map<String, Object> spanAssertions = (Map<String, Object>) intrinsics.get("Span");
    Map<String, Object> connectInfo = new HashMap<>();
    connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, accountId);
    connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, accountKey);
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
    distributedTraceService.connected(null, agentConfig);
    Transaction.clearTransaction();
    TransactionActivity.clear();
    spanEventsService.clearReservoir();
    Transaction tx = Transaction.getTransaction();
    TransactionData transactionData = new TransactionData(tx, 0);
    TransactionStats transactionStats = transactionData.getTransaction().getTransactionActivity().getTransactionStats();
    SamplingPriorityQueue<SpanEvent> eventPool = spanEventsService.getOrCreateDistributedSamplingReservoir(APP_NAME);
    Tracer rootTracer;
    if (webTransaction) {
        rootTracer = TransactionAsyncUtility.createDispatcherTracer(this, "WebTransaction");
    } else {
        rootTracer = TransactionAsyncUtility.createOtherTracer("OtherTransaction");
    }
    tx.getTransactionActivity().tracerStarted(rootTracer);
    if (raisesException) {
        tx.setThrowable(new Throwable(), TransactionErrorPriority.API, false);
    }
    setTransportType(tx, transportType);
    if (inbound_payloads != null) {
        for (Object payload : inbound_payloads) {
            tx.acceptDistributedTracePayload(payload.toString());
        }
    } else {
        tx.acceptDistributedTracePayload((String) null);
    }
    if (forceSampledTrue) {
        tx.setPriorityIfNotNull(new Random().nextFloat() + 1.0f);
    }
    if (outbound_payloads != null) {
        for (Object assertion : outbound_payloads) {
            JSONObject payloadAssertions = (JSONObject) assertion;
            DistributedTracePayload payload = new BoundTransactionApiImpl(tx).createDistributedTracePayload();
            assertOutboundPayload(payloadAssertions, payload);
        }
    }
    rootTracer.finish(Opcodes.RETURN, 0);
    distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
    ((SpanEventsServiceImpl) spanEventsService).dispatcherTransactionFinished(transactionData, transactionStats);
    List<SpanEvent> spans = eventPool.asList();
    TransactionEvent transactionEvent = ServiceFactory.getTransactionEventsService().createEvent(transactionData, transactionStats, "wat");
    JSONObject txnEvents = serializeAndParseEvents(transactionEvent);
    assertExpectedMetrics(expectedMetrics, transactionStats);
    for (Object event : targetEvents) {
        if (event.toString().startsWith("Transaction") && transactionAssertions != null) {
            assertTransactionEvents(transactionAssertions, txnEvents);
            assertTransactionEvents(commonAssertions, txnEvents);
        } else if (event.toString().startsWith("Span") && spanAssertions != null) {
            assertNotEquals("Expected some spans!", 0, spans.size());
            assertSpanEvents(spanAssertions, spans);
            assertSpanEvents(commonAssertions, spans);
        }
    }
}
Also used : HashMap(java.util.HashMap) Tracer(com.newrelic.agent.tracers.Tracer) DistributedTracePayload(com.newrelic.api.agent.DistributedTracePayload) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) AgentConfig(com.newrelic.agent.config.AgentConfig) TransactionEvent(com.newrelic.agent.service.analytics.TransactionEvent) TransactionStats(com.newrelic.agent.stats.TransactionStats) Random(java.util.Random) JSONObject(org.json.simple.JSONObject) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanEvent(com.newrelic.agent.model.SpanEvent) JSONObject(org.json.simple.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 49 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method unexpectedStringInTransaction.

@Test
public void unexpectedStringInTransaction() {
    TransactionData transactionData = createTransactionData(200, new ReportableError("Surprising error"), false);
    TransactionService txService = ServiceFactory.getTransactionService();
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(transactionData, transactionStats);
    List<TracedError> tracedErrors = ServiceFactory.getRPMService().getErrorService().getAndClearTracedErrors();
    TracedError tracedError = tracedErrors.get(0);
    Assert.assertEquals("Surprising error", tracedError.getMessage());
    Assert.assertFalse(tracedError.expected);
    Assert.assertTrue(tracedError.incrementsErrorMetric());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionService(com.newrelic.agent.TransactionService) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 50 with TransactionStats

use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.

the class ErrorServiceTest method expectedStringInTransaction.

@Test
public void expectedStringInTransaction() {
    TransactionData transactionData = createTransactionData(200, new ReportableError("I am expected"), true);
    TransactionService txService = ServiceFactory.getTransactionService();
    TransactionStats transactionStats = new TransactionStats();
    txService.transactionFinished(transactionData, transactionStats);
    List<TracedError> tracedErrors = ServiceFactory.getRPMService().getErrorService().getAndClearTracedErrors();
    TracedError tracedError = tracedErrors.get(0);
    Assert.assertEquals("I am expected", tracedError.getMessage());
    Assert.assertTrue(tracedError.expected);
    Assert.assertFalse(tracedError.incrementsErrorMetric());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionService(com.newrelic.agent.TransactionService) TransactionData(com.newrelic.agent.TransactionData) 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