use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class SpanParentTest method executeCrossProcessOnlyTest.
@Trace(dispatcher = true)
private void executeCrossProcessOnlyTest() throws IOException, URISyntaxException {
Transaction txn = ServiceFactory.getServiceManager().getTransactionService().getTransaction(false);
DistributedTracePayloadImpl payload = DistributedTracePayloadImpl.createDistributedTracePayload(null, txn.getGuid(), txn.getGuid(), 1.0f);
txn.acceptDistributedTracePayload(payload.httpSafe());
try (HttpTestServer server = HttpServerLocator.createAndStart()) {
nonExternalOrDatastore();
executeHttpRequest(false, server.getEndPoint().getPort());
executeFakeDatastoreRequest();
}
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class TraceAccessorApiTest method testAcceptPayloadGetSpanId.
@Test
public void testAcceptPayloadGetSpanId() throws Exception {
EnvironmentHolder holder = setupEnvironemntHolder("all_enabled_test");
try {
DistributedTracePayloadImpl distributedTracePayload = getDistributedTracePayload();
// We don't care about the DT payload transaction, so we will harvest and clear the tx list before continuing
harvestAndCheckTxn(holder);
TransactionDataList transactionList = holder.getTransactionList();
transactionList.clear();
String spanId = startTxAcceptPayloadAndReturnSpanId(distributedTracePayload);
harvestAndCheckTxn(holder);
Tracer rootTracer = transactionList.get(0).getRootTracer();
String expectedGuid = rootTracer.getGuid();
assertEquals(expectedGuid, spanId);
} finally {
holder.close();
}
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class TracerToSpanEventTest method testParentIdFromDTPayload.
@Test
public void testParentIdFromDTPayload() {
// setup
String parentGuid = "98765";
expectedIntrinsicAttributes.put("parentId", parentGuid);
SpanEvent expectedSpanEvent = buildExpectedSpanEvent();
DistributedTracePayloadImpl dtPayload = mock(DistributedTracePayloadImpl.class);
when(dtPayload.getGuid()).thenReturn(parentGuid);
when(txnData.getInboundDistributedTracePayload()).thenReturn(dtPayload);
TracerToSpanEvent testClass = new TracerToSpanEvent(errorBuilderMap, new AttributeFilter.PassEverythingAttributeFilter(), timestampProvider, environmentService, transactionDataToDistributedTraceIntrinsics, spanErrorBuilder);
// execution
SpanEvent spanEvent = testClass.createSpanEvent(tracer, txnData, txnStats, isRoot, false);
// assertions
assertEquals(expectedSpanEvent, spanEvent);
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class TracerToSpanEvent method createSpanEvent.
public SpanEvent createSpanEvent(Tracer tracer, TransactionData transactionData, TransactionStats transactionStats, boolean isRoot, boolean crossProcessOnly) {
SpanProxy spanProxy = transactionData.getSpanProxy();
DistributedTracePayloadImpl inboundPayload = spanProxy.getInboundDistributedTracePayload();
SpanEventFactory builder = new SpanEventFactory(transactionData.getApplicationName(), filter, timestampSupplier).setGuid(tracer.getGuid()).setTraceId(spanProxy.getOrCreateTraceId()).setSampled(transactionData.sampled()).setParentId(getParentId(tracer, transactionData, crossProcessOnly)).setTransactionId(transactionData.getGuid()).setDurationInSeconds((float) tracer.getDuration() / TimeConversion.NANOSECONDS_PER_SECOND).setName(tracer.getTransactionSegmentName()).setTimestamp(tracer.getStartTimeInMillis()).setPriority(transactionData.getPriority()).setExternalParameterAttributes(tracer.getExternalParameters()).setIsRootSpanEvent(isRoot).setDecider(inboundPayload == null || inboundPayload.priority == null);
builder = maybeSetError(tracer, transactionData, isRoot, builder);
builder = maybeSetGraphQLAttributes(tracer, builder);
W3CTraceState traceState = spanProxy.getInitiatingW3CTraceState();
if (traceState != null) {
if (isRoot && traceState.getGuid() != null) {
builder.setTrustedParent(traceState.getGuid());
}
Set<String> vendorKeys = W3CTraceStateSupport.buildVendorKeys(traceState);
builder.setTracingVendors(vendorKeys);
}
LimitedSizeHashMap<String, Object> spanUserAttributes = new LimitedSizeHashMap<>(MAX_USER_ATTRIBUTES);
// order matters here because we don't want transaction attributes to overwrite tracer attributes. This would be the case if there were 64
// transaction attributes and they got added first to the span attributes map. Then none of the tracer attributes would make it in due
// to the limit of 64 attributes.
spanUserAttributes.putAll(tracer.getCustomAttributes());
if (isRoot) {
copyTransactionAttributesToRootSpanBuilder(builder, transactionData, spanUserAttributes, transactionStats);
}
builder.putAllUserAttributes(spanUserAttributes);
return builder.build();
}
use of com.newrelic.agent.tracing.DistributedTracePayloadImpl in project newrelic-java-agent by newrelic.
the class SlowQueryInfo method createParameters.
@SuppressWarnings("unchecked")
private Map<String, Object> createParameters(Tracer tracer) {
Map<String, Object> parameters = new HashMap<>();
// Check for an explain plan (right now this only potentially exists for a SqlTracer)
Object explainPlan = tracer.getAgentAttribute(SqlTracer.EXPLAIN_PLAN_PARAMETER_NAME);
if (explainPlan != null) {
parameters.put(SlowQueryAggregatorImpl.EXPLAIN_PLAN_KEY, explainPlan);
}
// A backtrace could exist for any type of tracer
List<StackTraceElement> backtrace = (List<StackTraceElement>) tracer.getAgentAttribute(DefaultTracer.BACKTRACE_PARAMETER_NAME);
if (backtrace != null) {
backtrace = StackTraces.scrubAndTruncate(backtrace);
List<String> backtraceStrings = StackTraces.toStringList(backtrace);
parameters.put(SlowQueryAggregatorImpl.BACKTRACE_KEY, backtraceStrings);
}
DatastoreConfig datastoreConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getDatastoreConfig();
String host = (String) tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_HOST);
String port_path_or_id = (String) tracer.getAgentAttribute(DatastoreMetrics.DATASTORE_PORT_PATH_OR_ID);
boolean allUnknown = host == null && port_path_or_id == null;
if (datastoreConfig.isInstanceReportingEnabled() && !allUnknown) {
parameters.put(DatastoreMetrics.DATASTORE_HOST, host);
parameters.put(DatastoreMetrics.DATASTORE_PORT_PATH_OR_ID, port_path_or_id);
}
String databaseName = (String) tracer.getAgentAttribute(DatastoreMetrics.DB_INSTANCE);
if (datastoreConfig.isDatabaseNameReportingEnabled() && databaseName != null) {
parameters.put(DatastoreMetrics.DB_INSTANCE, databaseName);
}
// An input query could exist for any type of tracer and records ORM-like query strings
Map<String, String> inputQuery = (Map<String, String>) tracer.getAgentAttribute(DatastoreMetrics.INPUT_QUERY_ATTRIBUTE);
if (inputQuery != null) {
parameters.put(DatastoreMetrics.INPUT_QUERY_ATTRIBUTE, inputQuery);
}
Transaction txn = tracer.getTransactionActivity().getTransaction();
DistributedTracePayloadImpl inboundPayload = txn.getSpanProxy().getInboundDistributedTracePayload();
DistributedTraceService distributedTraceService = ServiceFactory.getDistributedTraceService();
DistributedTracingConfig distributedTracingConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getDistributedTracingConfig();
if (distributedTracingConfig.isEnabled()) {
String traceId = txn.getOrCreateTraceId();
String parentId = inboundPayload == null ? null : inboundPayload.txnId;
String parentSpanId = inboundPayload == null ? null : inboundPayload.guid;
Map<String, Object> intrinsics = distributedTraceService.getIntrinsics(inboundPayload, txn.getGuid(), traceId, txn.getTransportType(), txn.getTransportDurationInMillis(), txn.getLargestTransportDurationInMillis(), parentId, parentSpanId, txn.getPriority());
parameters.putAll(intrinsics);
}
parameters.put("priority", txn.getPriority());
return parameters;
}
Aggregations