Search in sources :

Example 11 with SpanEventsServiceImpl

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

the class DefaultTracerTest method testParent.

@Test
public void testParent() {
    DefaultTracer tracer = prepareTracer();
    Tracer child = new DefaultTracer(tracer.getTransaction(), new ClassMethodSignature("com.package.modern.Customer", "child", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
    tracer.getTransactionActivity().tracerStarted(child);
    Tracer child2 = new DefaultTracer(tracer.getTransaction(), new ClassMethodSignature("com.package.modern.Customer", "child2", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
    child.getTransactionActivity().tracerStarted(child2);
    child2.reportAsExternal(DatastoreParameters.product("YourSQL").collection("collection").operation("query").instance("databaseServer", 1234).databaseName("dbName").build());
    child2.finish(0, null);
    child.finish(0, null);
    Tracer sibiling = new DefaultTracer(tracer.getTransaction(), new ClassMethodSignature("com.package.modern.Customer", "sibiling", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
    tracer.getTransactionActivity().tracerStarted(sibiling);
    sibiling.reportAsExternal(HttpParameters.library("library").uri(URI.create("https://myservice:8080/api")).procedure("call").noInboundHeaders().build());
    sibiling.finish(0, null);
    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(4, spanEvents.size());
    SpanEvent rootSpan = null;
    SpanEvent childSpan = null;
    SpanEvent child2Span = null;
    SpanEvent siblingSpan = null;
    for (SpanEvent spanEvent : spanEvents) {
        if (spanEvent.getGuid().equals(tracer.getGuid())) {
            rootSpan = spanEvent;
        } else if (spanEvent.getGuid().equals(child.getGuid())) {
            childSpan = spanEvent;
        } else if (spanEvent.getGuid().equals(child2.getGuid())) {
            child2Span = spanEvent;
        } else if (spanEvent.getGuid().equals(sibiling.getGuid())) {
            siblingSpan = spanEvent;
        }
    }
    assertNotNull(rootSpan);
    assertNotNull(childSpan);
    assertNotNull(child2Span);
    assertNotNull(siblingSpan);
    assertEquals(tracer.getTransaction().getGuid(), rootSpan.getTransactionId());
    assertEquals(tracer.getTransaction().getGuid(), childSpan.getTransactionId());
    assertEquals(tracer.getTransaction().getGuid(), child2Span.getTransactionId());
    assertEquals(tracer.getTransaction().getGuid(), siblingSpan.getTransactionId());
    assertNull(rootSpan.getParentId());
    assertEquals(true, rootSpan.getIntrinsics().get("nr.entryPoint"));
    assertEquals(rootSpan.getGuid(), childSpan.getParentId());
    assertEquals(child.getGuid(), child2Span.getParentId());
    assertNull(child2Span.getIntrinsics().get("nr.entryPoint"));
    assertEquals(rootSpan.getGuid(), siblingSpan.getParentId());
    assertNull(siblingSpan.getIntrinsics().get("nr.entryPoint"));
    assertEquals("YourSQL", child2Span.getIntrinsics().get("component"));
    assertEquals("databaseServer", child2Span.getIntrinsics().get("peer.hostname"));
    assertEquals("dbName", child2Span.getIntrinsics().get("db.instance"));
    assertEquals("databaseServer:1234", child2Span.getIntrinsics().get("peer.address"));
    assertEquals("client", child2Span.getIntrinsics().get("span.kind"));
    assertEquals("library", siblingSpan.getIntrinsics().get("component"));
    assertEquals("client", siblingSpan.getIntrinsics().get("span.kind"));
    assertEquals("call", siblingSpan.getAgentAttributes().get("http.method"));
    assertEquals("https://myservice:8080/api", siblingSpan.getAgentAttributes().get("http.url"));
}
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 12 with SpanEventsServiceImpl

use of com.newrelic.agent.service.analytics.SpanEventsServiceImpl 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());
}
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 13 with SpanEventsServiceImpl

use of com.newrelic.agent.service.analytics.SpanEventsServiceImpl 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"));
}
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 14 with SpanEventsServiceImpl

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

the class DefaultTracerTest method testSpanParentingEvent.

@Test
public void testSpanParentingEvent() {
    DefaultTracer tracer = prepareTracer();
    tracer.finish(0, null);
    SpanProxy spanProxy = tracer.getTransaction().getSpanProxy();
    W3CTraceParentHeader.create(spanProxy, "12341234123412341234123412341234", "0101010101010101", false);
    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);
    Assert.assertNotEquals("0101010101010101", spanEvent.getParentId());
}
Also used : TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanProxy(com.newrelic.agent.tracing.SpanProxy) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

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