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);
}
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();
}
}
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);
}
}
}
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));
}
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);
}
Aggregations