use of com.newrelic.api.agent.DistributedTracePayload in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method testMultiTransactionSpanEvents.
@Test
public void testMultiTransactionSpanEvents() {
DistributedTraceServiceImpl dts = (DistributedTraceServiceImpl) ServiceFactory.getServiceManager().getDistributedTraceService();
Map<String, Object> configMap = ImmutableMap.<String, Object>builder().put("cross_application_tracer", ImmutableMap.builder().put("cross_process_id", "12345#whatever").put("trusted_account_key", "67890").build()).build();
dts.connected(null, AgentConfigFactory.createAgentConfig(configMap, null, null));
DefaultTracer firstTracer = prepareTracer();
BoundTransactionApiImpl firstTxn = new BoundTransactionApiImpl(firstTracer.getTransaction());
DistributedTracePayload payload = firstTxn.createDistributedTracePayload();
firstTracer.finish(0, null);
Transaction.clearTransaction();
DefaultTracer secondTracer = prepareTracer();
BoundTransactionApiImpl secondTxn = new BoundTransactionApiImpl(secondTracer.getTransaction());
secondTxn.acceptDistributedTracePayload(payload);
DistributedTracePayload secondPayload = secondTxn.createDistributedTracePayload();
secondTracer.finish(0, null);
Transaction.clearTransaction();
DefaultTracer thirdTracer = prepareTracer();
BoundTransactionApiImpl thirdTxn = new BoundTransactionApiImpl(thirdTracer.getTransaction());
thirdTxn.acceptDistributedTracePayload(secondPayload);
DistributedTracePayload thirdPayload = thirdTxn.createDistributedTracePayload();
thirdTracer.finish(0, null);
Transaction.clearTransaction();
DefaultTracer fourthTracer = prepareTracer();
BoundTransactionApiImpl fourthTxn = new BoundTransactionApiImpl(fourthTracer.getTransaction());
fourthTxn.acceptDistributedTracePayload(thirdPayload);
fourthTracer.finish(0, null);
SpanEventsService spanEventService = ServiceFactory.getSpanEventService();
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(firstTracer.getTransaction(), 1024), new TransactionStats());
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(secondTracer.getTransaction(), 1024), new TransactionStats());
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(thirdTracer.getTransaction(), 1024), new TransactionStats());
((SpanEventsServiceImpl) spanEventService).dispatcherTransactionFinished(new TransactionData(fourthTracer.getTransaction(), 1024), new TransactionStats());
SamplingPriorityQueue<SpanEvent> eventPool = spanEventService.getOrCreateDistributedSamplingReservoir(APP_NAME);
List<SpanEvent> spanEvents = eventPool.asList();
assertNotNull(spanEvents);
assertEquals(4, spanEvents.size());
// Make sure traceIds of all span events matches trace id of first payload sent
DistributedTracePayloadImpl parsedPayload = new DistributedTracePayloadParser(NewRelic.getAgent().getMetricAggregator(), ServiceFactory.getDistributedTraceService(), Agent.LOG).parse(null, payload.text());
assertNotNull(parsedPayload);
for (SpanEvent event : spanEvents) {
assertEquals("Span events must have same trace id", parsedPayload.traceId, event.getTraceId());
}
}
Aggregations