Search in sources :

Example 21 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanIdOnErrorsTest method assertMethodWhereErrorOriginatedHasThisSpanId.

private void assertMethodWhereErrorOriginatedHasThisSpanId(Object spanId, String expectedSpanName) {
    List<String> seenSpanNames = new LinkedList<>();
    for (SpanEvent spanEvent : ServiceFactory.getSpanEventService().getOrCreateDistributedSamplingReservoir(APP_NAME).asList()) {
        if (spanEvent.getGuid().equals(spanId)) {
            assertEquals(expectedSpanName, spanEvent.getName());
            return;
        } else {
            seenSpanNames.add(spanEvent.getName() + " id " + spanEvent.getGuid());
        }
    }
    assertEquals("Didn't find the span named " + expectedSpanName + " with id " + spanId, Collections.singletonList(expectedSpanName + " id " + spanId), seenSpanNames);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) LinkedList(java.util.LinkedList)

Example 22 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanParentTest method testSpanAndTransactionParenting.

@Test
public void testSpanAndTransactionParenting() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
    executeSpanAndTransactionParentingTest();
    try {
        TransactionDataList transactionList = holder.getTransactionList();
        assertEquals(2, transactionList.size());
        TransactionData tx1 = transactionList.get(0);
        TransactionData tx2 = transactionList.get(1);
        Collection<Tracer> tracers1 = tx1.getTracers();
        // Only a "rootTracer" on this transaction (root tracer is not in this list)
        assertEquals(0, tracers1.size());
        Collection<Tracer> tracers2 = tx2.getTracers();
        // 1 "rootTracer" (not in this list) + 2 non-external/datastore tracers + 2 external datastore tracers
        assertEquals(4, tracers2.size());
        SpanEventsService spanEventsService = ServiceFactory.getServiceManager().getSpanEventsService();
        String appName = ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName();
        SamplingPriorityQueue<SpanEvent> spanEventsPool = spanEventsService.getOrCreateDistributedSamplingReservoir(appName);
        assertNotNull(spanEventsPool);
        List<SpanEvent> spanEvents = spanEventsPool.asList();
        spanEventsPool.clear();
        assertNotNull(spanEvents);
        assertEquals(6, spanEvents.size());
        SpanEvent rootSpanEvent = null;
        Set<String> spanEventGuids = new HashSet<>();
        for (SpanEvent spanEvent : spanEvents) {
            if (spanEvent.getParentId() == null) {
                rootSpanEvent = spanEvent;
            }
            spanEventGuids.add(spanEvent.getGuid());
        }
        assertNotNull(rootSpanEvent);
        assertEquals(6, spanEventGuids.size());
        // Ensure that spans are only parented to other spans
        for (SpanEvent spanEvent : spanEvents) {
            if (spanEvent.getParentId() == null) {
                continue;
            }
            assertTrue(spanEventGuids.contains(spanEvent.getParentId()));
        }
        TransactionEventsService transactionEventsService = ServiceFactory.getServiceManager().getTransactionEventsService();
        DistributedSamplingPriorityQueue<TransactionEvent> txEventPool = transactionEventsService.getOrCreateDistributedSamplingReservoir(appName);
        assertNotNull(txEventPool);
        List<TransactionEvent> txEvents = txEventPool.asList();
        txEventPool.clear();
        assertNotNull(txEvents);
        assertEquals(2, txEvents.size());
        TransactionEvent parent = null;
        TransactionEvent child = null;
        for (TransactionEvent txEvent : txEvents) {
            if (txEvent.getParentId() == null) {
                parent = txEvent;
            } else {
                child = txEvent;
            }
        }
        assertNotNull(parent);
        assertNotNull(child);
        assertNull(parent.getParentId());
        assertEquals(parent.getGuid(), child.getParentId());
    } finally {
        holder.close();
    }
}
Also used : EnvironmentHolder(test.newrelic.test.agent.EnvironmentHolder) Tracer(com.newrelic.agent.tracers.Tracer) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) TransactionDataList(com.newrelic.agent.TransactionDataList) TransactionEvent(com.newrelic.agent.service.analytics.TransactionEvent) TransactionEventsService(com.newrelic.agent.service.analytics.TransactionEventsService) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Example 23 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class TransactionAttributesOnSpanTest method testFilteringOfCustomParametersAndCustomAttributesOnSpans.

@Test
public void testFilteringOfCustomParametersAndCustomAttributesOnSpans() {
    Map<String, String> expectedUserAttributesServiceEntrySpan = new HashMap<>();
    Map<String, String> expectedUserAttributesSecondSpan = new HashMap<>();
    expectedUserAttributesServiceEntrySpan.put("txAttrib0", "txValue0");
    expectedUserAttributesServiceEntrySpan.put("txAttrib1", "txValue1");
    expectedUserAttributesServiceEntrySpan.put("txAttrib3", "txValue3");
    expectedUserAttributesServiceEntrySpan.put("txAttrib4", "txValue4");
    expectedUserAttributesSecondSpan.put("spanAttrib0", "spanValue0");
    transactionLaunchPoint(6, 2);
    List<SpanEvent> spanEvents = spanEventPool.asList();
    for (SpanEvent span : spanEvents) {
        if (span.getIntrinsics().containsKey("nr.entryPoint")) {
            assertEquals(span.getUserAttributesCopy(), expectedUserAttributesServiceEntrySpan);
        } else {
            assertEquals(span.getUserAttributesCopy(), expectedUserAttributesSecondSpan);
        }
    }
}
Also used : HashMap(java.util.HashMap) SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Example 24 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class SpanEventSenderTest method pollAndWrite_ObserverReadySpanAvailableWrites.

@Test
void pollAndWrite_ObserverReadySpanAvailableWrites() {
    SpanEvent spanEvent = buildSpanEvent();
    doReturn(true).when(target).awaitReadyObserver(observer);
    doReturn(spanEvent).when(target).pollSafely();
    target.pollAndWrite();
    verify(target).writeToObserver(observer, SpanConverter.convert(spanEvent));
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) SpanConverterTest.buildSpanEvent(com.newrelic.SpanConverterTest.buildSpanEvent) Test(org.junit.jupiter.api.Test)

Example 25 with SpanEvent

use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.

the class DistributedSamplingPriorityQueueTest method testDefaultSort.

@Test
public void testDefaultSort() {
    DistributedSamplingPriorityQueue<SpanEvent> eventPool = new DistributedSamplingPriorityQueue<>(10);
    seedEventPool(eventPool);
    List<SpanEvent> spanEvents = eventPool.asList();
    Set<String> highPriorityGuids = Sets.newHashSet("1", "4", "7");
    Set<String> mediumPriorityGuids = Sets.newHashSet("2", "5", "8");
    Set<String> lowPriorityGuids = Sets.newHashSet("3", "6", "9");
    // Should be sorted by priority (default sort)
    SpanEvent event = Iterables.get(spanEvents, 0);
    assertNotNull(event);
    assertTrue(highPriorityGuids.contains(event.getGuid()));
    assertEquals(5.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 1);
    assertNotNull(event);
    assertTrue(highPriorityGuids.contains(event.getGuid()));
    assertEquals(5.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 2);
    assertNotNull(event);
    assertTrue(highPriorityGuids.contains(event.getGuid()));
    assertEquals(5.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 3);
    assertNotNull(event);
    assertTrue(mediumPriorityGuids.contains(event.getGuid()));
    assertEquals(3.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 4);
    assertNotNull(event);
    assertTrue(mediumPriorityGuids.contains(event.getGuid()));
    assertEquals(3.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 5);
    assertNotNull(event);
    assertTrue(mediumPriorityGuids.contains(event.getGuid()));
    assertEquals(3.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 6);
    assertNotNull(event);
    assertTrue(lowPriorityGuids.contains(event.getGuid()));
    assertEquals(1.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 7);
    assertNotNull(event);
    assertTrue(lowPriorityGuids.contains(event.getGuid()));
    assertEquals(1.0f, event.getPriority(), 0.0f);
    event = Iterables.get(spanEvents, 8);
    assertNotNull(event);
    assertTrue(lowPriorityGuids.contains(event.getGuid()));
    assertEquals(1.0f, event.getPriority(), 0.0f);
}
Also used : SpanEvent(com.newrelic.agent.model.SpanEvent) Test(org.junit.Test)

Aggregations

SpanEvent (com.newrelic.agent.model.SpanEvent)81 Test (org.junit.Test)64 AttributeFilter (com.newrelic.agent.model.AttributeFilter)23 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)19 TransactionStats (com.newrelic.agent.stats.TransactionStats)14 TransactionData (com.newrelic.agent.TransactionData)12 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)12 Tracer (com.newrelic.agent.tracers.Tracer)9 HashMap (java.util.HashMap)8 Map (java.util.Map)5 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)4 TransactionDataList (com.newrelic.agent.TransactionDataList)3 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)3 Test (org.junit.jupiter.api.Test)3 SpanConverterTest.buildSpanEvent (com.newrelic.SpanConverterTest.buildSpanEvent)2 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 AttributesService (com.newrelic.agent.attributes.AttributesService)2 AgentConfig (com.newrelic.agent.config.AgentConfig)2 ReservoirManager (com.newrelic.agent.interfaces.ReservoirManager)2 Consumer (com.newrelic.agent.interfaces.backport.Consumer)2