Search in sources :

Example 6 with DistributedTracePayload

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());
    }
}
Also used : BoundTransactionApiImpl(com.newrelic.agent.BoundTransactionApiImpl) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) DistributedTracePayload(com.newrelic.api.agent.DistributedTracePayload) SpanEventsService(com.newrelic.agent.service.analytics.SpanEventsService) DistributedTracePayloadParser(com.newrelic.agent.tracing.DistributedTracePayloadParser) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) TransactionStats(com.newrelic.agent.stats.TransactionStats) SpanEventsServiceImpl(com.newrelic.agent.service.analytics.SpanEventsServiceImpl) SpanEvent(com.newrelic.agent.model.SpanEvent) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Aggregations

DistributedTracePayload (com.newrelic.api.agent.DistributedTracePayload)6 Test (org.junit.Test)5 SpanEvent (com.newrelic.agent.model.SpanEvent)3 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)3 TransactionStats (com.newrelic.agent.stats.TransactionStats)3 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 Transaction (com.newrelic.agent.Transaction)2 TransactionData (com.newrelic.agent.TransactionData)2 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)2 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)2 Tracer (com.newrelic.agent.tracers.Tracer)2 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)2 DistributedTracePayloadParser (com.newrelic.agent.tracing.DistributedTracePayloadParser)2 DistributedTraceServiceImpl (com.newrelic.agent.tracing.DistributedTraceServiceImpl)2 NoOpDistributedTracePayload (com.newrelic.agent.bridge.NoOpDistributedTracePayload)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)1 ErrorEvent (com.newrelic.agent.model.ErrorEvent)1 AbstractTracer (com.newrelic.agent.tracers.AbstractTracer)1 ArrayList (java.util.ArrayList)1