use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class SpanParentTest method testCrossProcessOnly.
@Test
public void testCrossProcessOnly() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("cross_process_only_test");
executeCrossProcessOnlyTest();
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(2, spanEvents.size());
SpanEvent externalSpanEvent = null;
SpanEvent datastoreSpanEvent = null;
for (SpanEvent spanEvent : spanEvents) {
if (spanEvent.getCategory() == SpanCategory.http) {
externalSpanEvent = spanEvent;
} else if (spanEvent.getCategory() == SpanCategory.datastore) {
datastoreSpanEvent = spanEvent;
}
}
assertNotNull(externalSpanEvent);
assertNotNull(datastoreSpanEvent);
// For right now, we are putting cross-process only mode on ice. Poor orphan spans :(
assertNull(externalSpanEvent.getParentId());
assertNull(datastoreSpanEvent.getParentId());
} finally {
holder.close();
}
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class TransactionAttributesOnSpanTest method testCustomParameterAndAttributeOnSpans.
@Test
public void testCustomParameterAndAttributeOnSpans() {
String expectedSpanName = "Java/test.newrelic.test.agent.spans.TransactionAttributesOnSpanTest/transactionLaunchPoint";
transactionLaunchPoint(1, 1);
int numberOfSpansWithSpanAttribute = 0;
String spanNameWithTransactionAttribute = null;
List<SpanEvent> spanEvents = spanEventPool.asList();
for (SpanEvent span : spanEvents) {
if (span.getUserAttributesCopy().containsKey("txAttrib0")) {
assertNull("Span, " + span.getName() + ", should not have a transaction attribute. The attribute " + "is already on " + spanNameWithTransactionAttribute, spanNameWithTransactionAttribute);
assertEquals(expectedSpanName, span.getName());
spanNameWithTransactionAttribute = span.getName();
}
if (span.getUserAttributesCopy().containsKey("spanAttrib0")) {
numberOfSpansWithSpanAttribute++;
}
}
assertEquals(1, numberOfSpansWithSpanAttribute);
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class SpanEventSender method pollAndWrite.
@VisibleForTesting
void pollAndWrite() {
// Get stream observer
ClientCallStreamObserver<V1.Span> observer = channelManager.getSpanObserver();
// Confirm the observer is ready
if (!awaitReadyObserver(observer)) {
return;
}
// Poll queue for span
SpanEvent span = pollSafely();
if (span == null) {
return;
}
// Convert span and write to observer
V1.Span convertedSpan = SpanConverter.convert(span);
writeToObserver(observer, convertedSpan);
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class InfiniteTracingTest method accept_IncrementsCounterAndOffersToQueue.
@Test
@Timeout(1)
void accept_IncrementsCounterAndOffersToQueue() {
SpanEvent spanEvent = SpanEvent.builder().build();
target.accept(spanEvent);
verify(aggregator).incrementCounter("Supportability/InfiniteTracing/Span/Seen");
assertEquals(spanEvent, queue.poll());
}
use of com.newrelic.agent.model.SpanEvent in project newrelic-java-agent by newrelic.
the class SpanConverterTest method convert_Valid.
@Test
void convert_Valid() throws IOException {
SpanEvent spanEvent = buildSpanEvent();
V1.Span result = SpanConverter.convert(spanEvent);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
result.writeTo(baos);
V1.Span deserialized = V1.Span.parseFrom(baos.toByteArray());
assertEquals("abc123", deserialized.getTraceId());
assertEquals("abc123", deserialized.getIntrinsicsOrThrow("traceId").getStringValue());
assertEquals("my app", deserialized.getIntrinsicsOrThrow("appName").getStringValue());
assertEquals("value", deserialized.getIntrinsicsOrThrow("intrStr").getStringValue());
assertEquals(12345, deserialized.getIntrinsicsOrThrow("intrInt").getIntValue());
assertEquals(3.14, deserialized.getIntrinsicsOrThrow("intrFloat").getDoubleValue(), 0.00001);
assertTrue(deserialized.getIntrinsicsOrThrow("intrBool").getBoolValue());
assertFalse(deserialized.containsIntrinsics("intrOther"));
}
Aggregations