Search in sources :

Example 6 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class TransactionTest method testAcceptCreatePayload.

@Test
public void testAcceptCreatePayload() throws Exception {
    Map<String, Object> configMap = createNRDTConfigMap(false);
    createServiceManager(configMap);
    serviceManager.setDistributedTraceService(mockDistributedTraceService);
    Transaction.clearTransaction();
    Tracer dispatcherTracer = createDispatcherTracer(true);
    Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
    transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
    String inboundPayload = "{" + "  \"v\": [0,2]," + "  \"d\": {" + "    \"ty\": \"Mobile\"," + "    \"ac\": \"9123\"," + "    \"tk\": \"67890\"," + "    \"ap\": \"51424\"" + "    \"id\": \"27856f70d3d314b7\"," + "    \"tr\": \"3221bf09aa0bcf0d\"," + "    \"pr\": 0.999993," + "    \"ti\": 1482959525577" + "  }" + "}";
    transaction.acceptDistributedTracePayload(inboundPayload);
    String spanId = "meatball99";
    DistributedTracePayloadImpl payload = transaction.createDistributedTracePayload(spanId);
    DistributedTracePayloadImpl secondPayload = transaction.createDistributedTracePayload(spanId);
    dispatcherTracer.finish(Opcodes.ARETURN, null);
    assertEquals("App", payload.parentType);
    assertEquals(spanId, payload.guid);
    assertEquals("3221bf09aa0bcf0d", payload.traceId);
    assertNotNull(transaction.getSpanProxy().getInboundDistributedTracePayload());
    assertEquals("Mobile", transaction.getSpanProxy().getInboundDistributedTracePayload().parentType);
    assertEquals(0.999993f, payload.priority, 0.0f);
    assertEquals("App", secondPayload.parentType);
    assertEquals("3221bf09aa0bcf0d", secondPayload.traceId);
    assertEquals(spanId, secondPayload.guid);
    assertEquals(0.999993f, secondPayload.priority, 0.0f);
}
Also used : BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Test(org.junit.Test) SegmentTest(com.newrelic.agent.transaction.SegmentTest)

Example 7 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class TransactionDataTestBuilder method build.

public TransactionData build() {
    when(tx.getRootTracer()).thenReturn(tracer);
    if (synJobId == null || synMonitorId == null || synResourceId == null) {
        when(tx.isSynthetic()).thenReturn(false);
    } else {
        when(tx.isSynthetic()).thenReturn(true);
    }
    when(tx.getGuid()).thenReturn("guid");
    Dispatcher mockDispatcher = mock(Dispatcher.class);
    when(mockDispatcher.getUri()).thenReturn(requestUri);
    when(mockDispatcher.isWebTransaction()).thenReturn(dispatcher == null ? true : dispatcher.isWebTransaction());
    when(tx.getDispatcher()).thenReturn(mockDispatcher);
    if (throwable != null) {
        when(tx.getThrowable()).thenReturn(new TransactionThrowable(throwable, expectedError, null));
    }
    PriorityTransactionName priorityTransactionName = mock(PriorityTransactionName.class);
    when(priorityTransactionName.getName()).thenReturn(frontendMetricName);
    when(tx.getPriorityTransactionName()).thenReturn(priorityTransactionName);
    Map<String, Map<String, String>> prefixed = new HashMap<>();
    prefixed.put("request.parameters.", requestParams);
    when(tx.getPrefixedAgentAttributes()).thenReturn(prefixed);
    when(tx.getUserAttributes()).thenReturn(userParams);
    when(tx.getAgentAttributes()).thenReturn(agentParams);
    when(tx.getErrorAttributes()).thenReturn(errorParams);
    when(tx.getIntrinsicAttributes()).thenReturn(intrinsics);
    when(tx.isIgnore()).thenReturn(false);
    when(tx.getStatus()).thenReturn(responseStatus);
    when(tx.getStatusMessage()).thenReturn(statusMessage);
    when(tx.isErrorReportableAndNotIgnored()).thenReturn(true);
    when(tx.getSpanProxy()).thenReturn(new SpanProxy());
    ErrorServiceImpl errorService = mock(ErrorServiceImpl.class);
    IRPMService rpmService = mock(IRPMService.class);
    when(rpmService.getApplicationName()).thenReturn(appName);
    when(rpmService.getErrorService()).thenReturn(errorService);
    when(tx.getRPMService()).thenReturn(rpmService);
    when(tx.getAgentConfig()).thenReturn(agentConfig);
    when(tx.getWallClockStartTimeMs()).thenReturn(startTime);
    if (slowQueryListener != null) {
        when(tx.getSlowQueryListener(anyBoolean())).thenReturn(slowQueryListener);
    }
    when(tx.getTracers()).thenReturn(tracers);
    CrossProcessTransactionState crossProcessTransactionState = mock(CrossProcessTransactionState.class);
    when(tx.getCrossProcessTransactionState()).thenReturn(crossProcessTransactionState);
    when(crossProcessTransactionState.getTripId()).thenReturn("tripId");
    InboundHeaderState ihs = mock(InboundHeaderState.class);
    when(ihs.getSyntheticsJobId()).thenReturn(synJobId);
    when(ihs.getSyntheticsMonitorId()).thenReturn(synMonitorId);
    when(ihs.getSyntheticsResourceId()).thenReturn(synResourceId);
    when(ihs.getSyntheticsVersion()).thenReturn(HeadersUtil.SYNTHETICS_MIN_VERSION);
    when(tx.getInboundHeaderState()).thenReturn(ihs);
    TransactionTimer timer = new TransactionTimer(tracer.getStartTime());
    timer.markTransactionActivityAsDone(tracer.getEndTime(), tracer.getDuration());
    timer.markTransactionAsDone();
    when(tx.getTransactionTimer()).thenReturn(timer);
    // when(tx.getApplicationName()).thenReturn(appName);
    Set<TransactionActivity> activities = new HashSet<>();
    for (Map.Entry<Long, Collection<Duration>> entry : threadIdToDuration.asMap().entrySet()) {
        for (Duration duration : entry.getValue()) {
            TransactionActivity activity = mock(TransactionActivity.class);
            when(activity.getThreadId()).thenReturn(entry.getKey());
            Tracer rootTracer = mock(Tracer.class);
            when(rootTracer.getStartTime()).thenReturn(duration.startTime);
            when(rootTracer.getEndTime()).thenReturn(duration.endTime);
            when(activity.getRootTracer()).thenReturn(rootTracer);
            activities.add(activity);
        }
    }
    when(tx.getFinishedChildren()).thenReturn(activities);
    if (includeDistributedTracePayload) {
        SpanProxy spanProxy = mock(SpanProxy.class);
        DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload("abc", "def", "def", new Random().nextFloat());
        when(spanProxy.getInboundDistributedTracePayload()).thenReturn(payload);
        when(tx.getSpanProxy()).thenReturn(spanProxy);
    }
    return new TransactionData(tx, 0);
}
Also used : ErrorServiceImpl(com.newrelic.agent.errors.ErrorServiceImpl) HashMap(java.util.HashMap) SpanProxy(com.newrelic.agent.tracing.SpanProxy) Tracer(com.newrelic.agent.tracers.Tracer) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Random(java.util.Random) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) Collection(java.util.Collection) TransactionTimer(com.newrelic.agent.transaction.TransactionTimer) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 8 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class SpanParentTest method txnStarter.

@Trace(dispatcher = true)
private Header txnStarter(boolean noticeError) {
    Transaction txn = ServiceFactory.getServiceManager().getTransactionService().getTransaction(false);
    DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload(null, txn.getGuid(), txn.getGuid(), 1.0f);
    txn.acceptDistributedTracePayload(payload.httpSafe());
    MessagingTestServer server = new MessagingTestServer(8093);
    Header header = null;
    if (noticeError) {
        NewRelic.noticeError(new RuntimeException("I am something"));
    }
    try {
        server.start();
        header = runTestMessagingAPI();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        server.stop();
    }
    return header;
}
Also used : Transaction(com.newrelic.agent.Transaction) Header(org.apache.http.Header) MessagingTestServer(test.newrelic.test.agent.api.MessagingTestServer) IOException(java.io.IOException) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl)

Example 9 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class TraceAccessorApiTest method testAcceptPayloadGetTraceId.

@Test
public void testAcceptPayloadGetTraceId() throws Exception {
    EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
    try {
        DistributedTracePayloadImpl distributedTracePayload = getDistributedTracePayload();
        // We don't care about the DT payload transaction, so we will harvest and clear the tx list before continuing
        harvestAndCheckTxn(holder);
        TransactionDataList transactionList = holder.getTransactionList();
        transactionList.clear();
        startTxAcceptPayloadAndAssertTraceIdDoesNotEqualTransactionGuid(distributedTracePayload);
        harvestAndCheckTxn(holder);
    } finally {
        holder.close();
    }
}
Also used : TransactionDataList(com.newrelic.agent.TransactionDataList) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Test(org.junit.Test)

Example 10 with DistributedTracePayloadImpl

use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.

the class TraceAccessorApiTest method startTxCreatePayloadAndAssertTraceIdEqualsTransactionGuid.

@Trace(dispatcher = true)
private void startTxCreatePayloadAndAssertTraceIdEqualsTransactionGuid() {
    DistributedTracePayloadImpl distributedTracePayload = (DistributedTracePayloadImpl) NewRelic.getAgent().getTransaction().createDistributedTracePayload();
    String traceId = AgentBridge.getAgent().getTraceMetadata().getTraceId();
    // Creating a payload should not change the traceId
    assertEquals(distributedTracePayload.traceId, traceId);
}
Also used : DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Trace(com.newrelic.api.agent.Trace)

Aggregations

DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)22 Test (org.junit.Test)8 Tracer (com.newrelic.agent.tracers.Tracer)6 SpanProxy (com.newrelic.agent.tracing.SpanProxy)5 Transaction (com.newrelic.agent.Transaction)4 SpanEvent (com.newrelic.agent.model.SpanEvent)3 TransactionStats (com.newrelic.agent.stats.TransactionStats)3 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)3 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)3 DistributedTraceService (com.newrelic.agent.tracing.DistributedTraceService)3 SegmentTest (com.newrelic.agent.transaction.SegmentTest)3 BoundTransactionApiImpl (com.newrelic.agent.BoundTransactionApiImpl)2 TransactionData (com.newrelic.agent.TransactionData)2 TransactionDataList (com.newrelic.agent.TransactionDataList)2 DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)2 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)2 SpanEventsService (com.newrelic.agent.service.analytics.SpanEventsService)2 SpanEventsServiceImpl (com.newrelic.agent.service.analytics.SpanEventsServiceImpl)2 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)2