Search in sources :

Example 1 with SpanEventsServiceImpl

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) InetSocketAddress(java.net.InetSocketAddress) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SpanEvent(com.newrelic.agent.model.SpanEvent) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

Example 2 with SpanEventsServiceImpl

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());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) InetSocketAddress(java.net.InetSocketAddress) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) Connection(java.sql.Connection) DummyConnection(sql.DummyConnection) SpanEvent(com.newrelic.agent.model.SpanEvent) DummyResultSet(sql.DummyResultSet) Test(org.junit.Test)

Example 3 with SpanEventsServiceImpl

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);
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 4 with SpanEventsServiceImpl

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"));
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 5 with SpanEventsServiceImpl

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);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) TransactionService(com.newrelic.agent.TransactionService) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) MockServiceManager(com.newrelic.agent.MockServiceManager) AttributesService(com.newrelic.agent.attributes.AttributesService) MockRPMServiceManager(com.newrelic.agent.MockRPMServiceManager) AgentImpl(com.newrelic.agent.AgentImpl) Before(org.junit.Before)

Aggregations

SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)14 SpanEvent (com.newrelic.agent.model.SpanEvent)12 TransactionStats (com.newrelic.agent.stats.TransactionStats)11 Test (org.junit.Test)11 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)10 TransactionData (com.newrelic.agent.TransactionData)7 AgentConfig (com.newrelic.agent.config.AgentConfig)3 DistributedTracePayload (com.newrelic.api.agent.DistributedTracePayload)3 InetSocketAddress (java.net.InetSocketAddress)3 Connection (java.sql.Connection)3 DummyConnection (sql.DummyConnection)3 DummyResultSet (sql.DummyResultSet)3 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)2 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)2 DistributedTracePayloadParser (com.newrelic.agent.tracing.DistributedTracePayloadParser)2 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)2 AgentImpl (com.newrelic.agent.AgentImpl)1 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)1 MockServiceManager (com.newrelic.agent.MockServiceManager)1