Search in sources :

Example 1 with SyntheticsIds

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

the class TransactionEventTest method testJsonWithSyntheticIds.

@Test
public void testJsonWithSyntheticIds() throws Exception {
    float duration = 0.001931f;
    TransactionEvent event = baseBuilder(duration).setSyntheticsIds(new SyntheticsIds("101", "102", "103")).build();
    JSONArray jsonArray = (JSONArray) AgentHelper.serializeJSON(event);
    JSONObject jsonObject = (JSONObject) jsonArray.get(0);
    assertEquals(12, jsonObject.size());
    assertEquals("101", jsonObject.get("nr.syntheticsResourceId"));
    assertEquals("102", jsonObject.get("nr.syntheticsMonitorId"));
    assertEquals("103", jsonObject.get("nr.syntheticsJobId"));
}
Also used : SyntheticsIds(com.newrelic.agent.model.SyntheticsIds) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) Test(org.junit.Test)

Example 2 with SyntheticsIds

use of com.newrelic.agent.model.SyntheticsIds 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)

Aggregations

SyntheticsIds (com.newrelic.agent.model.SyntheticsIds)2 CountedDuration (com.newrelic.agent.model.CountedDuration)1 PathHashes (com.newrelic.agent.model.PathHashes)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