use of com.newrelic.agent.tracing.DistributedTraceService in project newrelic-java-agent by newrelic.
the class Transaction method checkAndSetPriority.
private void checkAndSetPriority() {
if (getAgentConfig().getDistributedTracingConfig().isEnabled()) {
DistributedTraceService distributedTraceService = ServiceFactory.getDistributedTraceService();
DistributedTracePayloadImpl inboundPayload = spanProxy.get().getInboundDistributedTracePayload();
Float inboundPriority = inboundPayload != null ? inboundPayload.priority : null;
DistributedSamplingPriorityQueue<TransactionEvent> reservoir = ServiceFactory.getTransactionEventsService().getOrCreateDistributedSamplingReservoir(getApplicationName());
priority.compareAndSet(null, distributedTraceService.calculatePriority(inboundPriority, reservoir));
} else {
priority.compareAndSet(null, DistributedTraceServiceImpl.nextTruncatedFloat());
}
}
use of com.newrelic.agent.tracing.DistributedTraceService in project newrelic-java-agent by newrelic.
the class TransactionTest method testWithNullPriorityDoesNotResetPriority.
@Test
public void testWithNullPriorityDoesNotResetPriority() throws Exception {
Map<String, Object> configMap = createConfigMap();
configMap.put(AgentConfigImpl.DISTRIBUTED_TRACING, ImmutableMap.of("enabled", Boolean.TRUE));
createServiceManager(configMap);
serviceManager.setDistributedTraceService(new DistributedTraceService() {
@Override
public boolean isEnabled() {
return true;
}
@Override
public int getMajorSupportedCatVersion() {
return 1;
}
@Override
public int getMinorSupportedCatVersion() {
return 0;
}
@Override
public String getAccountId() {
return "9123";
}
@Override
public String getApplicationId() {
return "1234";
}
@Override
public <T extends PriorityAware> float calculatePriority(Float priority, SamplingPriorityQueue<T> reservoir) {
return 0.678f;
}
@Override
public Map<String, Object> getIntrinsics(DistributedTracePayloadImpl inboundPayload, String guid, String traceId, TransportType transportType, long parentTransportDuration, long largestTransportDuration, String parentId, String parentSpanId, float priority) {
return null;
}
@Override
public String getTrustKey() {
return "67890";
}
@Override
public DistributedTracePayload createDistributedTracePayload(Tracer tracer) {
return null;
}
});
Transaction.clearTransaction();
Tracer dispatcherTracer = createDispatcherTracer(true);
Transaction transaction = dispatcherTracer.getTransactionActivity().getTransaction();
transaction.getTransactionActivity().tracerStarted(dispatcherTracer);
String inboundPayload = "{" + " \"v\": [0,2]," + " \"d\": {" + " \"ty\": \"Mobile\"," + " \"ac\": \"9123\"," + " \"tk\": \"67890\"," + " \"ap\": \"51424\"" + " \"id\": \"27856f70d3d314b7\"," + " \"tr\": \"3221bf09aa0bcf0d\"," + " \"pr\": null," + " \"ti\": 1482959525577" + " }" + "}";
transaction.acceptDistributedTracePayload(inboundPayload);
String spanId = "meatball101";
DistributedTracePayloadImpl payload = transaction.createDistributedTracePayload(spanId);
DistributedTracePayloadImpl secondPayload = transaction.createDistributedTracePayload(spanId);
dispatcherTracer.finish(Opcodes.ARETURN, null);
// Verify that when the inbound priority is null, that we retain our priority.
assertEquals("Mobile", transaction.getSpanProxy().getInboundDistributedTracePayload().parentType);
assertEquals(0.678f, payload.priority, 0.0f);
// Verify that the payload that gets passed on will preserve the priority we created.
assertEquals("App", secondPayload.parentType);
assertEquals("3221bf09aa0bcf0d", secondPayload.traceId);
assertEquals(spanId, secondPayload.guid);
assertEquals(0.678f, secondPayload.priority, 0.0f);
}
use of com.newrelic.agent.tracing.DistributedTraceService in project newrelic-java-agent by newrelic.
the class ErrorServiceImpl method createTracedError.
private TracedError createTracedError(final String theAppName, TransactionData td, Throwable throwable, int responseStatus, String statusMessage) {
TracedError error;
// noticeError(expected = true)?
boolean responseStatusExpected = errorCollectorConfig.getExpectedStatusCodes().contains(responseStatus);
boolean throwableExpected = td.getThrowable() == null ? false : td.getThrowable().expected;
boolean markedExpected = responseStatusExpected || throwableExpected;
Map<String, Object> joinedIntrinsics = new HashMap<>(td.getIntrinsicAttributes());
DistributedTraceService distributedTraceService = ServiceFactory.getDistributedTraceService();
DistributedTracingConfig distributedTracingConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getDistributedTracingConfig();
if (distributedTracingConfig.isEnabled()) {
joinedIntrinsics.putAll(distributedTraceService.getIntrinsics(td.getInboundDistributedTracePayload(), td.getGuid(), td.getTraceId(), td.getTransportType(), td.getTransportDurationInMillis(), td.getLargestTransportDurationInMillis(), td.getParentId(), td.getParentSpanId(), td.getPriority()));
}
if (throwable != null) {
error = ThrowableError.builder(errorCollectorConfig, theAppName, td.getBlameOrRootMetricName(), throwable, td.getWallClockStartTimeMs()).errorMessageReplacer(errorMessageReplacer).requestUri(td.getRequestUri(AgentConfigImpl.ERROR_COLLECTOR)).prefixedAttributes(td.getPrefixedAttributes()).userAttributes(td.getUserAttributes()).agentAttributes(td.getAgentAttributes()).errorAttributes(td.getErrorAttributes()).intrinsicAttributes(joinedIntrinsics).expected(markedExpected).build();
} else {
error = HttpTracedError.builder(errorCollectorConfig, theAppName, td.getBlameOrRootMetricName(), td.getWallClockStartTimeMs()).statusCodeAndMessage(responseStatus, statusMessage).transactionData(td).requestUri(td.getRequestUri(AgentConfigImpl.ERROR_COLLECTOR)).prefixedAttributes(td.getPrefixedAttributes()).userAttributes(td.getUserAttributes()).agentAttributes(td.getAgentAttributes()).errorAttributes(td.getErrorAttributes()).intrinsicAttributes(joinedIntrinsics).expected(markedExpected).build();
}
return error;
}
use of com.newrelic.agent.tracing.DistributedTraceService in project newrelic-java-agent by newrelic.
the class ErrorEventFactory method getDistributedTraceIntrinsics.
private static Map<String, Object> getDistributedTraceIntrinsics(TransactionData transactionData) {
DistributedTracingConfig distributedTracingConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getDistributedTracingConfig();
if (!distributedTracingConfig.isEnabled()) {
return null;
}
// Better CAT
DistributedTraceService distributedTraceService = ServiceFactory.getDistributedTraceService();
return distributedTraceService.getIntrinsics(transactionData.getInboundDistributedTracePayload(), transactionData.getGuid(), transactionData.getTraceId(), transactionData.getTransportType(), transactionData.getTransportDurationInMillis(), transactionData.getLargestTransportDurationInMillis(), transactionData.getParentId(), transactionData.getParentSpanId(), transactionData.getPriority());
}
use of com.newrelic.agent.tracing.DistributedTraceService 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