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