Search in sources :

Example 1 with SpanEventsService

use of com.newrelic.agent.service.analytics.SpanEventsService in project newrelic-java-agent by newrelic.

the class SegmentTest method createServiceManager.

private static void createServiceManager(Map<String, Object> map, ExpirationService expirationService) throws Exception {
    ConfigService configService = ConfigServiceFactory.createConfigServiceUsingSettings(map);
    MockServiceManager serviceManager = new MockServiceManager(configService);
    ServiceFactory.setServiceManager(serviceManager);
    ThreadService threadService = new ThreadService();
    serviceManager.setThreadService(threadService);
    serviceManager.setConfigService(configService);
    StatsService statsService = new StatsServiceImpl();
    serviceManager.setStatsService(statsService);
    MockCoreService agent = new MockCoreService();
    serviceManager.setCoreService(agent);
    HarvestService harvestService = new MockHarvestService();
    serviceManager.setHarvestService(harvestService);
    AsyncTransactionService asyncTxService = new AsyncTransactionService();
    serviceManager.setAsyncTransactionService(asyncTxService);
    TransactionService transactionService = new TransactionService(2, 1, 3, TimeUnit.SECONDS);
    serviceManager.setTransactionService(transactionService);
    EnvironmentService envService = new EnvironmentServiceImpl();
    serviceManager.setEnvironmentService(envService);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
    SqlTraceService sqlTraceService = new SqlTraceServiceImpl();
    serviceManager.setSqlTraceService(sqlTraceService);
    serviceManager.setAttributesService(new AttributesService());
    DistributedTraceServiceImpl distributedTraceService = new DistributedTraceServiceImpl();
    Map<String, Object> configMap = ImmutableMap.<String, Object>builder().put("cross_application_tracer", ImmutableMap.builder().put("account_id", "12abc345").put("trusted_account_key", "12abc345").build()).build();
    distributedTraceService.connected(null, AgentConfigFactory.createAgentConfig(configMap, null, null));
    serviceManager.setDistributedTraceService(distributedTraceService);
    TransactionDataToDistributedTraceIntrinsics transactionDataToDistributedTraceIntrinsics = new TransactionDataToDistributedTraceIntrinsics(distributedTraceService);
    serviceManager.setTransactionEventsService(new TransactionEventsService(transactionDataToDistributedTraceIntrinsics));
    MockRPMServiceManager rpmServiceManager = new MockRPMServiceManager();
    serviceManager.setRPMServiceManager(rpmServiceManager);
    serviceManager.setExpirationService(expirationService);
    SpanEventsService spanEventsService = SpanEventsServiceFactory.builder().configService(configService).reservoirManager(new MockSpanEventReservoirManager(configService)).transactionService(serviceManager.getTransactionService()).rpmServiceManager(serviceManager.getRPMServiceManager()).spanEventCreationDecider(new SpanEventCreationDecider(configService)).environmentService(envService).transactionDataToDistributedTraceIntrinsics(transactionDataToDistributedTraceIntrinsics).build();
    serviceManager.setSpansEventService(spanEventsService);
    serviceManager.start();
}
Also used : StatsService(com.newrelic.agent.stats.StatsService) TransactionDataToDistributedTraceIntrinsics(com.newrelic.agent.service.analytics.TransactionDataToDistributedTraceIntrinsics) SpanEventCreationDecider(com.newrelic.agent.service.analytics.SpanEventCreationDecider) StatsServiceImpl(com.newrelic.agent.stats.StatsServiceImpl) SqlTraceServiceImpl(com.newrelic.agent.sql.SqlTraceServiceImpl) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) AttributesService(com.newrelic.agent.attributes.AttributesService) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) AsyncTransactionService(com.newrelic.agent.service.async.AsyncTransactionService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService) SqlTraceService(com.newrelic.agent.sql.SqlTraceService) ConfigService(com.newrelic.agent.config.ConfigService) EnvironmentServiceImpl(com.newrelic.agent.environment.EnvironmentServiceImpl) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) EnvironmentService(com.newrelic.agent.environment.EnvironmentService)

Example 2 with SpanEventsService

use of com.newrelic.agent.service.analytics.SpanEventsService in project newrelic-java-agent by newrelic.

the class SegmentTest method testSpanParenting.

@Test
public void testSpanParenting() {
    SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
    SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
    Transaction.clearTransaction();
    Tracer rootTracer = makeTransaction();
    rootTracer.getTransactionActivity().getTransaction().setPriorityIfNotNull(1.0f);
    rootTracer.setMetricName("RootTracer");
    Transaction tx = rootTracer.getTransactionActivity().getTransaction();
    Segment segment = tx.startSegment("custom", "segment");
    final HashMap<String, String> headers = new HashMap<>();
    segment.addOutboundRequestHeaders(new OutboundHeaders() {

        @Override
        public HeaderType getHeaderType() {
            return HeaderType.HTTP;
        }

        @Override
        public void setHeader(String name, String value) {
            headers.put(name, value);
        }
    });
    String payload = headers.get("newrelic");
    segment.end();
    rootTracer.finish(Opcodes.ARETURN, null);
    Transaction.clearTransaction();
    Tracer secondRootTracer = makeTransaction();
    secondRootTracer.setMetricName("SecondRootTracer");
    Transaction secondTxn = secondRootTracer.getTransactionActivity().getTransaction();
    secondTxn.acceptDistributedTracePayload(payload);
    secondRootTracer.finish(Opcodes.ARETURN, null);
    List<SpanEvent> spanEvents = eventPool.asList();
    Assert.assertNotNull(spanEvents);
    assertEquals(3, spanEvents.size());
    SpanEvent rootTracerSpanEvent = findSpanByName(spanEvents, "RootTracer");
    SpanEvent segmentSpanEvent = findSpanByName(spanEvents, "custom/segment");
    SpanEvent secondRootTracerSpanEvent = findSpanByName(spanEvents, "SecondRootTracer");
    assertEquals(rootTracerSpanEvent.getTraceId(), segmentSpanEvent.getTraceId());
    assertEquals(segmentSpanEvent.getTraceId(), secondRootTracerSpanEvent.getTraceId());
    assertEquals(rootTracerSpanEvent.getGuid(), segmentSpanEvent.getParentId());
    assertEquals(segmentSpanEvent.getGuid(), secondRootTracerSpanEvent.getParentId());
}
Also used : HashMap(java.util.HashMap) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) HeaderType(com.newrelic.api.agent.HeaderType) SpanEvent(com.newrelic.agent.model.SpanEvent) OutboundHeaders(com.newrelic.api.agent.OutboundHeaders) Test(org.junit.Test)

Example 3 with SpanEventsService

use of com.newrelic.agent.service.analytics.SpanEventsService 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 4 with SpanEventsService

use of com.newrelic.agent.service.analytics.SpanEventsService 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 5 with SpanEventsService

use of com.newrelic.agent.service.analytics.SpanEventsService 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)

Aggregations

SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)23 SpanEvent (com.newrelic.agent.model.SpanEvent)19 Test (org.junit.Test)18 TransactionStats (com.newrelic.agent.stats.TransactionStats)11 TransactionData (com.newrelic.agent.TransactionData)10 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)10 TransactionDataList (com.newrelic.agent.TransactionDataList)3 Tracer (com.newrelic.agent.tracers.Tracer)3 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)3 InetSocketAddress (java.net.InetSocketAddress)3 Connection (java.sql.Connection)3 DummyConnection (sql.DummyConnection)3 DummyResultSet (sql.DummyResultSet)3 EnvironmentHolder (test.newrelic.test.agent.EnvironmentHolder)3 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 TransactionListener (com.newrelic.agent.TransactionListener)2 AgentConfigListener (com.newrelic.agent.config.AgentConfigListener)2 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)2 TransactionEventsService (com.newrelic.agent.service.analytics.TransactionEventsService)2 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)2