use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class TracerToSpanEvent method getParentId.
private String getParentId(Tracer tracer, TransactionData transactionData, boolean crossProcessOnly) {
if (crossProcessOnly) {
// Cross process only uses transactionId for parenting instead of the parentId attribute so we do not have a parentId here
return null;
}
// This is the non cross_process_only case where we "parent" using the parent tracer
// or the inbound payload id if this is the first/root tracer and we have an inbound payload
Tracer parentSegment = AbstractTracer.getParentTracerWithSpan(tracer.getParentTracer());
if (parentSegment != null) {
return parentSegment.getGuid();
}
DistributedTracePayloadImpl inboundPayload = transactionData.getInboundDistributedTracePayload();
if (inboundPayload != null) {
// If we have an inbound payload we can use the id from the payload since it should be the id of the span that initiated this trace
return inboundPayload.getGuid();
}
if (transactionData.getW3CTraceParent() != null) {
return transactionData.getW3CTraceParent().getParentId();
}
return null;
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class TransactionDataToDistributedTraceIntrinsics method buildDistributedTracingIntrinsics.
public Map<String, Object> buildDistributedTracingIntrinsics(TransactionData transactionData, boolean addTransactionParentingAttributes) {
DistributedTracePayloadImpl inboundDistributedTracePayload = transactionData.getInboundDistributedTracePayload();
String parentId = null;
// only set parentId if a payload is received with tx guid
if (inboundDistributedTracePayload != null && inboundDistributedTracePayload.getTransactionId() != null) {
parentId = transactionData.getParentId();
}
String parentSpanId = null;
// only set parentSpanId if a payload is received with id guid
if ((inboundDistributedTracePayload != null && inboundDistributedTracePayload.getGuid() != null) || transactionData.getW3CTraceParent() != null) {
parentSpanId = transactionData.getParentSpanId();
}
Map<String, Object> intrinsics = distributedTraceService.getIntrinsics(inboundDistributedTracePayload, transactionData.getGuid(), transactionData.getTripId(), transactionData.getTransportType(), transactionData.getTransportDurationInMillis(), transactionData.getLargestTransportDurationInMillis(), parentId, parentSpanId, transactionData.getPriority());
if (!addTransactionParentingAttributes) {
return intrinsics;
}
intrinsics = new HashMap<>(intrinsics);
putIntrinsicIfNotNull(intrinsics, "parentId", parentId);
putIntrinsicIfNotNull(intrinsics, "parentSpanId", parentSpanId);
return intrinsics;
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl 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;
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class CrossProcessStateCatApiTest method setUpTransaction.
private void setUpTransaction(Transaction tx, TransactionActivity txa, Object lock, Dispatcher dispatcher, CrossProcessConfig config, String guid) {
when(txa.getTransaction()).thenReturn(tx);
when(tx.getLock()).thenReturn(lock);
when(tx.getDispatcher()).thenReturn(dispatcher);
when(tx.getCrossProcessConfig()).thenReturn(config);
DistributedTracePayloadImpl distributedTracePayload = DistributedTracePayloadImpl.createDistributedTracePayload("", "", "", 0f);
when(tx.createDistributedTracePayload(guid)).thenReturn(distributedTracePayload);
TransactionStats transactionStats = Mockito.mock(TransactionStats.class);
SimpleStatsEngine stats = Mockito.mock(SimpleStatsEngine.class);
when(stats.getOrCreateResponseTimeStats(anyString())).thenReturn(Mockito.mock(ResponseTimeStats.class));
when(transactionStats.getUnscopedStats()).thenReturn(stats);
when(txa.getTransactionStats()).thenReturn(transactionStats);
when(tx.getTransactionActivity()).thenReturn(txa);
InboundHeaders headers = Mockito.mock(InboundHeaders.class);
InboundHeaderState inboundHeaderState = new InboundHeaderState(tx, headers);
when(tx.getInboundHeaderState()).thenReturn(inboundHeaderState);
PriorityTransactionName priorityTransactionName = PriorityTransactionName.create("Something/Or/other", "category", TransactionNamePriority.FRAMEWORK);
when(tx.getPriorityTransactionName()).thenReturn(priorityTransactionName);
TransactionCounts txnCounts = Mockito.mock(TransactionCounts.class);
when(txnCounts.isOverTracerSegmentLimit()).thenReturn(false);
when(tx.getTransactionCounts()).thenReturn(txnCounts);
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class CrossProcessTransactionStateImplTest method setupTestForDistributedTracing.
private CrossProcessTransactionStateImpl setupTestForDistributedTracing(boolean includeNewRelicHeader) {
String encodingKey = "test";
String txGuid = "ee8e5ef1a374c0ec";
DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload("14", "15", txGuid, 1.678f);
when(crossProcessConfig.isCrossApplicationTracing()).thenReturn(true);
when(crossProcessConfig.getEncodingKey()).thenReturn(encodingKey);
when(distributedTracingConfig.isEnabled()).thenReturn(true);
when(distributedTracingConfig.isIncludeNewRelicHeader()).thenReturn(includeNewRelicHeader);
when(spanEventsConfig.isEnabled()).thenReturn(true);
when(transactionEventsConfig.isEnabled()).thenReturn(true);
when(tx.getPriorityTransactionName()).thenReturn(PriorityTransactionName.create("Test", "TEST", TransactionNamePriority.NONE));
when(tx.getApplicationName()).thenReturn("TestApp");
when(tx.getGuid()).thenReturn(txGuid);
when(tx.createDistributedTracePayload(anyString())).thenReturn(payload);
mockConfigFromTransaction();
InboundHeaderState ihs = mock(InboundHeaderState.class);
SpanProxy spanProxy = mock(SpanProxy.class);
when(tx.getInboundHeaderState()).thenReturn(ihs);
when(tx.sampled()).thenReturn(true);
when(tx.getMetricAggregator()).thenReturn(mock(MetricAggregator.class));
when(tx.getSpanProxy()).thenReturn(spanProxy);
W3CTraceParent traceParent = new W3CTraceParent("1.0", "traceId123abc", "parentId987", 11);
when(spanProxy.getInitiatingW3CTraceParent()).thenReturn(traceParent);
when(spanProxy.getOutboundDistributedTracePayload()).thenReturn(payload);
TransactionTraceService transactionTraceService = mock(TransactionTraceService.class);
serviceManager.setTransactionTraceService(transactionTraceService);
return CrossProcessTransactionStateImpl.create(tx);
}
Aggregations