Search in sources :

Example 1 with PathHashes

use of com.newrelic.agent.model.PathHashes in project newrelic-java-agent by newrelic.

the class TransactionEventsService method createEvent.

// public for testing purposes
public TransactionEvent createEvent(TransactionData transactionData, TransactionStats transactionStats, String metricName) {
    long startTime = transactionData.getWallClockStartTimeMs();
    long durationInNanos = transactionData.getLegacyDuration();
    boolean distributedTracingEnabled = ServiceFactory.getConfigService().getDefaultAgentConfig().getDistributedTracingConfig().isEnabled();
    Integer port = ServiceFactory.getEnvironmentService().getEnvironment().getAgentIdentity().getServerPort();
    String syntheticsResourceId = transactionData.getSyntheticsResourceId();
    String syntheticsMonitorId = transactionData.getSyntheticsMonitorId();
    String syntheticsJobId = transactionData.getSyntheticsJobId();
    SyntheticsIds syntheticsIds = new SyntheticsIds(syntheticsResourceId, syntheticsMonitorId, syntheticsJobId);
    TransactionEventBuilder eventBuilder = new TransactionEventBuilder().setAppName(transactionData.getApplicationName()).setTimestamp(startTime).setName(metricName).setDuration((float) durationInNanos / TimeConversion.NANOSECONDS_PER_SECOND).setGuid(transactionData.getGuid()).setReferringGuid(transactionData.getReferrerGuid()).setPort(port).setTripId(transactionData.getTripId()).setApdexPerfZone(transactionData.getApdexPerfZone()).setSyntheticsIds(syntheticsIds).setError(transactionData.hasReportableErrorThatIsNotIgnored()).setpTotalTime((float) transactionData.getTransactionTime().getTotalSumTimeInNanos() / TimeConversion.NANOSECONDS_PER_SECOND).setTimeoutCause(transactionData.getTransaction().getTimeoutCause()).setPriority(transactionData.getPriority());
    if (distributedTracingEnabled) {
        DistributedTracePayloadImpl inboundDistributedTracePayload = transactionData.getInboundDistributedTracePayload();
        eventBuilder = eventBuilder.setDecider(inboundDistributedTracePayload == null || inboundDistributedTracePayload.priority == null);
        Map<String, Object> distributedTraceServiceIntrinsics = transactionDataToDistributedTraceIntrinsics.buildDistributedTracingIntrinsics(transactionData, true);
        eventBuilder = eventBuilder.setDistributedTraceIntrinsics(distributedTraceServiceIntrinsics);
    }
    final boolean attributesEnabled = ServiceFactory.getAttributesService().isAttributesEnabledForTransactionEvents(transactionData.getApplicationName());
    if (attributesEnabled) {
        eventBuilder.putAllUserAttributes(transactionData.getUserAttributes());
    }
    Integer pathHash = null;
    if (transactionData.getTripId() != null) {
        pathHash = transactionData.generatePathHash();
    }
    PathHashes pathHashes = new PathHashes(pathHash, transactionData.getReferringPathHash(), transactionData.getAlternatePathHashes());
    eventBuilder.setPathHashes(pathHashes);
    if (transactionData.getTransactionTime().getTimeToFirstByteInNanos() > 0) {
        float timeToFirstByte = (float) transactionData.getTransactionTime().getTimeToFirstByteInNanos() / TimeConversion.NANOSECONDS_PER_SECOND;
        eventBuilder.setTimeToFirstByte(timeToFirstByte);
    }
    if (transactionData.getTransactionTime().getTimetoLastByteInNanos() > 0) {
        float timeToLastByte = (float) transactionData.getTransactionTime().getTimetoLastByteInNanos() / TimeConversion.NANOSECONDS_PER_SECOND;
        eventBuilder.setTimeToLastByte(timeToLastByte);
    }
    eventBuilder.setQueueDuration(retrieveMetricIfExists(transactionStats, MetricNames.QUEUE_TIME).getTotal());
    float externalDuration = retrieveMetricIfExists(transactionStats, MetricNames.EXTERNAL_ALL).getTotal();
    float externalCallCount = retrieveMetricIfExists(transactionStats, MetricNames.EXTERNAL_ALL).getCallCount();
    eventBuilder.setExternal(new CountedDuration(externalDuration, externalCallCount));
    float databaseDuration = retrieveMetricIfExists(transactionStats, DatastoreMetrics.ALL).getTotal();
    float databaseCallCount = retrieveMetricIfExists(transactionStats, DatastoreMetrics.ALL).getCallCount();
    eventBuilder.setDatabase(new CountedDuration(databaseDuration, databaseCallCount));
    float gcCumulative = retrieveMetricIfExists(transactionStats, MetricNames.GC_CUMULATIVE).getTotal();
    eventBuilder.setGcCumulative(gcCumulative);
    TransactionEvent event = eventBuilder.build();
    if (attributesEnabled) {
        // trans events take user and agent atts - any desired intrinsics should have already been grabbed
        event.agentAttributes = transactionData.getAgentAttributes();
        // request/message parameters are sent up in the same bucket as agent attributes
        event.agentAttributes.putAll(AttributesUtils.appendAttributePrefixes(transactionData.getPrefixedAttributes()));
    }
    return event;
}
Also used : SyntheticsIds(com.newrelic.agent.model.SyntheticsIds) CountedDuration(com.newrelic.agent.model.CountedDuration) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) PathHashes(com.newrelic.agent.model.PathHashes)

Example 2 with PathHashes

use of com.newrelic.agent.model.PathHashes in project newrelic-java-agent by newrelic.

the class TransactionEventTest method testJsonWithPathHashes.

@Test
public void testJsonWithPathHashes() throws Exception {
    float duration = 0.001931f;
    TransactionEvent event = baseBuilder(duration).setPathHashes(new PathHashes(12, 13, "14")).build();
    JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
    JSONObject jsonObject = (JSONObject) jsonArray.get(0);
    assertEquals(9, jsonObject.size());
    // These should only be set when using CAT, not DT as the agent does by default as of 7.3.0
    assertNull(jsonObject.get("nr.pathHash"));
    assertNull(jsonObject.get("nr.referringPathHash"));
    assertNull(jsonObject.get("nr.alternatePathHashes"));
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) PathHashes(com.newrelic.agent.model.PathHashes) Test(org.junit.Test)

Aggregations

PathHashes (com.newrelic.agent.model.PathHashes)2 CountedDuration (com.newrelic.agent.model.CountedDuration)1 SyntheticsIds (com.newrelic.agent.model.SyntheticsIds)1 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1