use of com.newrelic.agent.model.CountedDuration 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;
}
Aggregations