Search in sources :

Example 1 with DistributedTracePayloadBuilder

use of com.newrelic.agent.DistributedTracePayloadBuilder in project newrelic-java-agent by newrelic.

the class DistributedTraceServiceImplTest method txnFinishedInboundPayload.

@Test
public void txnFinishedInboundPayload() {
    Map<String, Object> connectInfo = new HashMap<>();
    connectInfo.put(DistributedTracingConfig.ACCOUNT_ID, "1acct234");
    connectInfo.put(DistributedTracingConfig.TRUSTED_ACCOUNT_KEY, "67890");
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, Collections.<String, Object>emptyMap(), connectInfo);
    distributedTraceService.connected(null, agentConfig);
    TransactionStats transactionStats = new TransactionStats();
    Map<String, Object> intrinsicAttributes = new HashMap<>();
    long payloadSendTimestamp = 1002000;
    long startTimeInMillis = 1005000;
    long responseTimeInNanos = TimeUnit.MILLISECONDS.toNanos(1350);
    String json = new DistributedTracePayloadBuilder().setTimestamp(payloadSendTimestamp).setHost("datanerd.us.com").setParentType("Browser").setAccountId("123456").setTrustKey("67890").setApplicationId("6789").setTransactionId("badcafe3").setTripId("cattrip").setPriority(0.0f).setDepth(0).setSyntheticsJob(null).setSyntheticsMonitor(null).setSyntheticsResource(null).createJsonPayload();
    DistributedTracePayloadImpl payload = new DistributedTracePayloadParser(NewRelic.getAgent().getMetricAggregator(), distributedTraceService, Agent.LOG).parse(null, json);
    TransactionData transactionData = createTransactionData(intrinsicAttributes, startTimeInMillis, responseTimeInNanos, payload);
    distributedTraceService.dispatcherTransactionFinished(transactionData, transactionStats);
    SimpleStatsEngine unscopedStats = transactionStats.getUnscopedStats();
    assertEquals(1.35f, unscopedStats.getOrCreateResponseTimeStats("DurationByCaller/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
    assertEquals(3.0f, unscopedStats.getOrCreateResponseTimeStats("TransportDuration/Browser/123456/6789/HTTPS/all").getTotal(), 0.01f);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) TransactionStats(com.newrelic.agent.stats.TransactionStats) DistributedTracePayloadBuilder(com.newrelic.agent.DistributedTracePayloadBuilder) HashMap(java.util.HashMap) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) TransactionData(com.newrelic.agent.TransactionData) Test(org.junit.Test)

Aggregations

DistributedTracePayloadBuilder (com.newrelic.agent.DistributedTracePayloadBuilder)1 TransactionData (com.newrelic.agent.TransactionData)1 AgentConfig (com.newrelic.agent.config.AgentConfig)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 TransactionStats (com.newrelic.agent.stats.TransactionStats)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1