use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsNoServerName.
@Test
public void requestXStartHeaderRecordMetricsNoServerName() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
long nowInMicroseconds = TimeUnit.MICROSECONDS.convert(Transaction.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
long requestStartTimeInMicroseconds = nowInMicroseconds - 10000;
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "t=" + requestStartTimeInMicroseconds);
WebRequestDispatcher dispatcher = createDispatcher(httpRequest);
dispatcher.transactionFinished("WebTransaction/Uri/test", stats);
long txStartTimeInMicroseconds = TimeUnit.MICROSECONDS.convert(dispatcher.getTransaction().getWallClockStartTimeMs(), TimeUnit.MILLISECONDS);
float expected = (float) (txStartTimeInMicroseconds - requestStartTimeInMicroseconds) / 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(expected, statsEngine.getUnscopedStats().getOrCreateResponseTimeStats(spec).getTotal(), .001);
Assert.assertEquals(1, statsEngine.getSize());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class BasicRequestDispatcherTracerTest method requestXStartHeaderRecordMetricsNoValue.
@Test
public void requestXStartHeaderRecordMetricsNoValue() throws Exception {
MockHttpRequest httpRequest = new MockHttpRequest();
httpRequest.setHeader(QueueTimeTracker.REQUEST_X_START_HEADER, "");
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 TransactionTraceTest method testDistributedTracingAtts.
@Test
public void testDistributedTracingAtts() throws Exception {
MockServiceManager serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
serviceManager.start();
Map<String, Object> config = new HashMap<>();
Map<String, Object> dtConfig = new HashMap<>();
dtConfig.put("enabled", true);
config.put("distributed_tracing", dtConfig);
Map<String, Object> spanConfig = new HashMap<>();
spanConfig.put("collect_span_events", true);
config.put("span_events", spanConfig);
config.put(AgentConfigImpl.APP_NAME, "TransactionTraceTest");
ConfigService configService = ConfigServiceFactory.createConfigService(AgentConfigImpl.createAgentConfig(config), config);
serviceManager.setConfigService(configService);
serviceManager.setAttributesService(new AttributesService());
serviceManager.setTransactionTraceService(new TransactionTraceService());
serviceManager.setTransactionService(new TransactionService());
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
serviceManager.setDistributedTraceService(distributedTraceService);
TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
serviceManager.setRPMServiceManager(new MockRPMServiceManager());
Transaction.clearTransaction();
Transaction transaction = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("class", "method", "desc");
OtherRootTracer tracer = new OtherRootTracer(transaction, sig, null, new SimpleMetricNameFormat("metric"));
transaction.getTransactionActivity().tracerStarted(tracer);
tracer.finish(Opcodes.ARETURN, null);
TransactionData td = new TransactionData(transaction, 0);
((DistributedTraceServiceImpl) ServiceFactory.getDistributedTraceService()).dispatcherTransactionFinished(td, new TransactionStats());
TransactionTrace trace = TransactionTrace.getTransactionTrace(td, SqlObfuscator.getDefaultSqlObfuscator());
Writer writer = new StringWriter();
trace.writeJSONString(writer);
JSONArray serializedTrace = (JSONArray) AgentHelper.serializeJSON(trace);
JSONArray traceDetails = (JSONArray) decodeTransactionTraceData(serializedTrace.get(4));
JSONObject atts = (JSONObject) traceDetails.get(4);
Map<String, Object> intrinsics = (Map<String, Object>) atts.get("intrinsics");
Assert.assertTrue(intrinsics.containsKey("traceId"));
Assert.assertTrue(intrinsics.containsKey("guid"));
Assert.assertTrue(intrinsics.containsKey("priority"));
Assert.assertTrue(intrinsics.containsKey("sampled"));
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method testSpanEventDatastore.
@Test
public void testSpanEventDatastore() throws SQLException {
final Connection connection = mock(Connection.class);
DatastoreInstanceDetection.detectConnectionAddress();
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();
DefaultSqlTracer tracer = newInstanceDBTracer("SELECT price, name FROM BOOKS WHERE price <= 79.99", connection, "MySQL", "mysql");
tracer.finish(Opcodes.ARETURN, new DummyResultSet());
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertEquals("datastore", spanEvent.getIntrinsics().get("category"));
assertEquals("MySQL", spanEvent.getIntrinsics().get("component"));
assertEquals("dbserver.nerd.us", spanEvent.getIntrinsics().get("peer.hostname"));
assertEquals("dbserver.nerd.us:9945", spanEvent.getIntrinsics().get("peer.address"));
assertEquals("SELECT price, name FROM BOOKS WHERE price <= 79.99", spanEvent.getIntrinsics().get("db.statement"));
assertEquals("books", spanEvent.getIntrinsics().get("db.collection"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
assertEquals("Datastore/statement/MySQL/books/select", spanEvent.getName());
assertNotNull(spanEvent.getTraceId());
assertNotNull(spanEvent.getGuid());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanEventDatastore.
@Test
public void testSpanEventDatastore() {
DefaultTracer tracer = prepareTracer();
tracer.reportAsExternal(DatastoreParameters.product("YourSQL").collection("collection").operation("query").instance("databaseServer", 1234).databaseName("dbName").build());
tracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(tracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(1, spanEvents.size());
SpanEvent spanEvent = Iterables.getFirst(spanEvents, null);
assertNotNull(spanEvent);
assertNull(spanEvent.getParentId());
assertEquals("YourSQL", spanEvent.getIntrinsics().get("component"));
assertEquals("databaseServer", spanEvent.getIntrinsics().get("peer.hostname"));
assertEquals("dbName", spanEvent.getIntrinsics().get("db.instance"));
assertEquals("databaseServer:1234", spanEvent.getIntrinsics().get("peer.address"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
}
Aggregations