use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class TransactionEventsServiceTest method testDifferentAppNamesOneDisabled.
@Test
public void testDifferentAppNamesOneDisabled() throws Exception {
setup(true, true, TEST_RESERVOIR_SIZE);
// server side says app name 2 disabled
Map<String, Object> data = new HashMap<>();
data.put("collect_analytics_events", Boolean.FALSE);
((ConfigServiceImpl) configService).connected(rpmServiceAppName2, data);
// default app name
TransactionData transactionData = generateTransactionData(APP_NAME);
TransactionStats transactionStats = new TransactionStats();
transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
// second app name
TransactionData transactionData2 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), APP_NAME_2);
TransactionStats transactionStats2 = new TransactionStats();
transactionStats2.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(9, TimeUnit.MILLISECONDS);
// third app name
String appName3 = "thirdAppName";
rpmServiceManager.getOrCreateRPMService(appName3);
TransactionData transactionData3 = generateTransactionDataAndComplete(Collections.<String, Object>emptyMap(), appName3);
TransactionStats transactionStats3 = new TransactionStats();
transactionStats3.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(10, TimeUnit.MILLISECONDS);
// populate the eventData map
service.harvestEvents(APP_NAME);
// populate the eventData map
service.harvestEvents(APP_NAME_2);
// populate the eventData map
service.harvestEvents(appName3);
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData2 = getEventData(APP_NAME_2);
assertEquals(0, currentEventData2.size());
DistributedSamplingPriorityQueue<TransactionEvent> currentEventData3 = getEventData(appName3);
assertEquals(0, currentEventData3.size());
service.dispatcherTransactionFinished(transactionData, transactionStats);
service.dispatcherTransactionFinished(transactionData2, transactionStats2);
service.dispatcherTransactionFinished(transactionData3, transactionStats3);
assertEquals(1, currentEventData.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData.peek().getDuration(), 0);
currentEventData2 = getEventData(APP_NAME_2);
assertNull(currentEventData2);
assertEquals(1, currentEventData3.size());
assertEquals(100f / TimeConversion.MILLISECONDS_PER_SECOND, currentEventData3.peek().getDuration(), 0);
service.harvestEvents(APP_NAME);
currentEventData = getEventData(APP_NAME);
assertEquals(0, currentEventData.size());
service.harvestEvents(appName3);
currentEventData3 = getEventData(appName3);
assertEquals(0, currentEventData3.size());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testNoParametersInUri.
@Test
public void testNoParametersInUri() {
DefaultTracer tracer = prepareTracer();
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);
assertEquals(uri, tracer.getTransactionSegmentUri());
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testGenericParametersNoHost.
@Test
public void testGenericParametersNoHost() {
DefaultTracer tracer = prepareTracer();
TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
URI uriWithNoHost = URI.create("../icons/logo.gif");
tracer.reportAsExternal(HttpParameters.library("library").uri(uriWithNoHost).procedure("procedure").noInboundHeaders().build());
tracer.recordMetrics(stats);
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanEventHttp.
@Test
public void testSpanEventHttp() {
DefaultTracer tracer = prepareTracer();
tracer.reportAsExternal(HttpParameters.library("library").uri(URI.create("http://www.newrelic.com")).procedure("call").noInboundHeaders().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("library", spanEvent.getIntrinsics().get("component"));
assertEquals("client", spanEvent.getIntrinsics().get("span.kind"));
assertEquals("http://www.newrelic.com", spanEvent.getAgentAttributes().get("http.url"));
assertEquals("call", spanEvent.getAgentAttributes().get("http.method"));
}
use of com.newrelic.agent.stats.TransactionStats in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testExternalParameters.
@Test
public void testExternalParameters() throws URISyntaxException {
TransactionActivity.clear();
Transaction.clearTransaction();
Transaction tx = Transaction.getTransaction();
TransactionActivity txa = TransactionActivity.get();
Tracer root = new OtherRootTracer(tx, new ClassMethodSignature("com.newrelic.agent.TracedActivityTest", "makeTransaction", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
txa.tracerStarted(root);
final TransactionStats stats = root.getTransactionActivity().getTransactionStats();
// http external
final String library = "unittest";
final URI uri = new URI("http://localhost");
final String host = uri.getHost();
final String procedure = "connect";
int externalCount = 0;
{
// generic external
DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
assertExternal(stats, externalCount, host, library, procedure);
// multiple calls to addExternalParameters should only apply the last call
tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
// metrics should only be recorded when the tracer finishes
assertExternal(stats, externalCount, host, library, procedure);
assertEquals(externalCount, stats.getScopedStats().getOrCreateResponseTimeStats("External/" + host + "/" + library + "/" + procedure).getCallCount());
tracer.finish(0, null);
externalCount++;
assertExternal(stats, externalCount, host, library, procedure);
assertEquals(externalCount, stats.getScopedStats().getOrCreateResponseTimeStats("External/" + host + "/" + library + "/" + procedure).getCallCount());
}
final DatastoreVendor vendor = DatastoreVendor.MySQL;
final String collection = "stores";
final String operation = "select";
final int port = 666;
int datastoreCount = 0;
{
// datastore
DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
tracer.reportAsExternal(DatastoreParameters.product(vendor.toString()).collection(collection).operation(operation).instance(host, port).build());
assertDatastore(stats, datastoreCount, vendor.toString(), collection, operation, host, port);
tracer.finish(0, null);
datastoreCount++;
assertDatastore(stats, datastoreCount, vendor.toString(), collection, operation, host, port);
// http external should be unchanged
assertExternal(stats, externalCount, host, library, procedure);
}
{
// http + DT
DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
tracer.addOutboundRequestHeaders(new Outbound());
tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
tracer.reportAsExternal(HttpParameters.library(library).uri(uri).procedure(procedure).inboundHeaders(new Inbound("Foo")).build());
assertCat(tracer, false);
assertExternal(stats, externalCount, host, library, procedure);
tracer.finish(0, null);
externalCount++;
// DT is enabled, there should not be any CAT
assertCat(tracer, false);
// ExternalTransaction/localhost/12345/Foo
assertExternal(stats, externalCount, host, library, procedure);
assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Foo").getCallCount());
}
{
// last inboundHeaders win
DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
tracer.addOutboundRequestHeaders(new Outbound());
tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
tracer.reportAsExternal(HttpParameters.library(library).uri(uri).procedure(procedure).inboundHeaders(new Inbound("Foo")).build());
// headers trump the previous call
tracer.readInboundResponseHeaders(new Inbound("Bar"));
assertCat(tracer, false);
assertExternal(stats, externalCount, host, library, procedure);
tracer.finish(0, null);
externalCount++;
// DT is enabled, there should not be any CAT
assertCat(tracer, false);
// ExternalTransaction/localhost/12345/Foo
assertExternal(stats, externalCount, host, library, procedure);
assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Bar").getCallCount());
}
{
// set headers manually
DefaultTracer tracer = (DefaultTracer) AgentBridge.instrumentation.createTracer(null, 0, "iamyourchild", DefaultTracer.DEFAULT_TRACER_FLAGS);
tracer.addOutboundRequestHeaders(new Outbound());
tracer.reportAsExternal(GenericParameters.library(library).uri(uri).procedure(procedure).build());
// headers trump the previous call
tracer.readInboundResponseHeaders(new Inbound("Baz"));
assertCat(tracer, false);
assertExternal(stats, externalCount, host, library, procedure);
tracer.finish(0, null);
externalCount++;
// DT is enabled, there should not be any CAT
assertCat(tracer, false);
// ExternalTransaction/localhost/12345/Foo
assertExternal(stats, externalCount, host, library, procedure);
assertEquals(0, stats.getScopedStats().getOrCreateResponseTimeStats("ExternalTransaction/" + host + "/12345/Baz").getCallCount());
}
root.finish(0, null);
}
Aggregations