use of com.newrelic.agent.service.analytics.SpanEventsServiceImpl in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method testSpanEventDatastoreTruncationAtExactLimit.
@Test
public void testSpanEventDatastoreTruncationAtExactLimit() throws SQLException {
final Connection connection = mock(Connection.class);
DatastoreInstanceDetection.detectConnectionAddress();
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();
String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 1957);
DefaultSqlTracer tracer = newInstanceDBTracer(longQueryString, 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(2000, spanEvent.getIntrinsics().get("db.statement").toString().length());
// Should not end with ... since it's exactly at the limit
assertTrue(spanEvent.getIntrinsics().get("db.statement").toString().endsWith("aaa"));
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.service.analytics.SpanEventsServiceImpl in project newrelic-java-agent by newrelic.
the class DefaultSqlTracerTest method testSpanEventDatastoreTruncation.
@Test
public void testSpanEventDatastoreTruncation() throws SQLException {
final Connection connection = mock(Connection.class);
DatastoreInstanceDetection.detectConnectionAddress();
DatastoreInstanceDetection.associateAddress(connection, new InetSocketAddress("dbserver.nerd.us", 9945));
DatastoreInstanceDetection.stopDetectingConnectionAddress();
String longQueryString = "SELECT price, name FROM BOOKS WHERE name = " + Strings.repeat("a", 4000);
DefaultSqlTracer tracer = newInstanceDBTracer(longQueryString, 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(2000, spanEvent.getIntrinsics().get("db.statement").toString().length());
assertTrue(spanEvent.getIntrinsics().get("db.statement").toString().endsWith("a..."));
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.service.analytics.SpanEventsServiceImpl in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testSpanEvent.
@Test
public void testSpanEvent() {
DefaultTracer tracer = prepareTracer();
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(tracer.getGuid(), spanEvent.getGuid());
assertEquals(tracer.getTransaction().getGuid(), spanEvent.getTransactionId());
assertEquals("Java/class/method", spanEvent.getName());
assertEquals(true, spanEvent.getIntrinsics().get("nr.entryPoint"));
assertEquals((float) tracer.getDurationInMilliseconds() / TimeConversion.MILLISECONDS_PER_SECOND, spanEvent.getDuration(), 0.001f);
}
use of com.newrelic.agent.service.analytics.SpanEventsServiceImpl 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.service.analytics.SpanEventsServiceImpl in project newrelic-java-agent by newrelic.
the class DistributedTracingApiTest method setup.
@Before
public void setup() throws Exception {
serviceManager = new MockServiceManager();
ServiceFactory.setServiceManager(serviceManager);
setupConfig(false);
serviceManager.setTransactionService(new TransactionService());
serviceManager.setAttributesService(new AttributesService());
AgentBridge.agent = new AgentImpl(Agent.LOG);
serviceManager.setRPMServiceManager(new MockRPMServiceManager());
ServiceFactory.getServiceManager().start();
DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
ServiceFactory.getTransactionService().addTransactionListener(distributedTraceService);
SpanEventsServiceImpl spanEventsService = SpanEventsServiceImpl.builder().agentConfig(agentConfig).build();
serviceManager.setDistributedTraceService(distributedTraceService);
serviceManager.setSpansEventService(spanEventsService);
Map<String, Object> connectInfo = ImmutableMap.<String, Object>of(ACCOUNT_ID, "33", TRUSTED_ACCOUNT_KEY, "33", PRIMARY_APPLICATION_ID, "2827902");
AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
distributedTraceService.connected(null, agentConfig);
}
Aggregations