Search in sources :

Example 6 with DistributedTracingConfig

use of com.newrelic.agent.config.DistributedTracingConfig in project newrelic-java-agent by newrelic.

the class DistributedTraceServiceImpl method connected.

@Override
public void connected(IRPMService rpmService, AgentConfig agentConfig) {
    DistributedTracingConfig dtConfig = agentConfig.getDistributedTracingConfig();
    String appId = String.valueOf(dtConfig.getPrimaryApplicationId());
    if (appId != null) {
        applicationId.set(appId);
    }
    String accId = String.valueOf(dtConfig.getAccountId());
    if (accId != null) {
        accountId.set(accId);
    }
    String trustedAccountKey = String.valueOf(dtConfig.getTrustedAccountKey());
    if (trustedAccountKey != null) {
        trustKey.set(trustedAccountKey);
    } else {
        trustKey.set(getAccountId());
    }
    // Fallback in case none of the previous attempts set the application ID
    applicationId.compareAndSet(null, "0");
}
Also used : DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig)

Example 7 with DistributedTracingConfig

use of com.newrelic.agent.config.DistributedTracingConfig in project newrelic-java-agent by newrelic.

the class CrossProcessTransactionStateImpl method getTripId.

/**
 * Get the trip ID. The trip ID is non-null if this object's owning Transaction is a "CAT participant". We are CAT
 * participant if either (1) the inbound request that initiated us contained a valid CAT header, or (2) we are a
 * "CAT originator", meaning we have originated at least one CAT transaction that instrumentation was able to
 * detect.
 *
 * @return the trip ID if we are a CAT participant or null if we aren't. Note that the return value can change
 * during the course of a transaction.
 */
@Override
public String getTripId() {
    AgentConfig agentConfig = tx.getAgentConfig();
    DistributedTracingConfig config = agentConfig.getDistributedTracingConfig();
    if (!config.isEnabled() && !tx.getCrossProcessConfig().isCrossApplicationTracing()) {
        return null;
    }
    if (tripId == null) {
        tripId = tx.getInboundHeaderState().getInboundTripId();
    }
    if (tripId == null && tx.getAgentConfig().getDistributedTracingConfig().isEnabled()) {
        tripId = tx.getSpanProxy().getTraceId();
    }
    if (tripId == null && this.isCatOriginator) {
        // never null
        tripId = tx.getGuid();
    }
    return tripId;
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig)

Example 8 with DistributedTracingConfig

use of com.newrelic.agent.config.DistributedTracingConfig 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());
}
Also used : DistributedTraceService(com.newrelic.agent.tracing.DistributedTraceService) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig)

Example 9 with DistributedTracingConfig

use of com.newrelic.agent.config.DistributedTracingConfig in project newrelic-java-agent by newrelic.

the class TransactionEvent method writeJSONString.

/*
     * The data should go up as 3 hashes. Example: [ { "webDuration":value, "databaseDuration":value, "timestamp":value,
     * "name":"value", "duration":value, "type":"value" }, { "user_param1":"value", "user_param2":value, }, {
     * "agent_param1": "value", "agent_param2": value }
     */
@SuppressWarnings("unchecked")
@Override
public void writeJSONString(Writer out) throws IOException {
    JSONObject obj = new JSONObject();
    obj.put("type", getType());
    obj.put("timestamp", getTimestamp());
    obj.put("name", name);
    obj.put("duration", timing.getDuration());
    obj.put("error", error);
    obj.put("totalTime", timing.getTotalTime());
    obj.put("priority", getPriority());
    if (timing.getTimeToFirstByte() != UNASSIGNED_FLOAT) {
        obj.put("timeToFirstByte", timing.getTimeToFirstByte());
    }
    if (timing.getTimeToLastByte() != UNASSIGNED_FLOAT) {
        obj.put("timeToLastByte", timing.getTimeToLastByte());
    }
    if (apdexPerfZone != null) {
        obj.put("apdexPerfZone", apdexPerfZone.getZone());
    }
    DistributedTracingConfig distributedTracingConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getDistributedTracingConfig();
    if (!distributedTracingConfig.isEnabled()) {
        if (tripId != null) {
            // prefixed to be hidden by Insights
            obj.put("nr.tripId", tripId);
        }
        if (guid != null) {
            // prefixed to be hidden by Insights
            obj.put("nr.guid", guid);
        }
        if (getPathHash() != null) {
            // properly handles leading 0's
            // prefixed to be hidden by Insights
            obj.put("nr.pathHash", String.format("%08x", getPathHash()));
        }
        if (getReferringPathHash() != null) {
            // properly handles leading 0's
            obj.put("nr.referringPathHash", String.format("%08x", getReferringPathHash()));
        }
        if (getAlternatePathHashes() != null) {
            // prefixed to be hidden by Insights
            obj.put("nr.alternatePathHashes", getAlternatePathHashes());
        }
        if (referrerGuid != null) {
            // prefixed to be hidden by Insights
            obj.put("nr.referringTransactionGuid", referrerGuid);
        }
    }
    if (this.syntheticsIds.getResourceId() != null) {
        obj.put("nr.syntheticsResourceId", this.syntheticsIds.getResourceId());
    }
    if (this.syntheticsIds.getMonitorId() != null) {
        obj.put("nr.syntheticsMonitorId", this.syntheticsIds.getMonitorId());
    }
    if (this.syntheticsIds.getJobId() != null) {
        obj.put("nr.syntheticsJobId", this.syntheticsIds.getJobId());
    }
    if (port != UNASSIGNED_INT) {
        obj.put("port", port);
    }
    if (timing.getQueueDuration() != UNASSIGNED_FLOAT) {
        obj.put("queueDuration", timing.getQueueDuration());
    }
    if (getExternalDuration() != UNASSIGNED_FLOAT) {
        obj.put("externalDuration", getExternalDuration());
    }
    if (getExternalCallCount() > 0) {
        obj.put("externalCallCount", getExternalCallCount());
    }
    if (getDatabaseDuration() != UNASSIGNED_FLOAT) {
        obj.put("databaseDuration", getDatabaseDuration());
    }
    if (getDatabaseCallCount() > 0) {
        obj.put("databaseCallCount", getDatabaseCallCount());
    }
    if (timing.getGcCumulative() != UNASSIGNED_FLOAT) {
        obj.put("gcCumulative", timing.getGcCumulative());
    }
    if (timeoutCause != null) {
        obj.put("nr.timeoutCause", timeoutCause.cause);
    }
    if (distributedTraceIntrinsics != null && !distributedTraceIntrinsics.isEmpty()) {
        obj.putAll(distributedTraceIntrinsics);
    }
    Map<String, ?> filteredUserAtts = getUserFilteredMap(getMutableUserAttributes());
    Map<String, ?> filteredAgentAtts = getFilteredMap(agentAttributes);
    if (filteredAgentAtts.isEmpty()) {
        if (filteredUserAtts.isEmpty()) {
            JSONArray.writeJSONString(Collections.singletonList(obj), out);
        } else {
            JSONArray.writeJSONString(Arrays.asList(obj, filteredUserAtts), out);
        }
    } else {
        JSONArray.writeJSONString(Arrays.asList(obj, filteredUserAtts, filteredAgentAtts), out);
    }
}
Also used : DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) JSONObject(org.json.simple.JSONObject)

Example 10 with DistributedTracingConfig

use of com.newrelic.agent.config.DistributedTracingConfig 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;
}
Also used : DistributedTraceService(com.newrelic.agent.tracing.DistributedTraceService) DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) HashMap(java.util.HashMap) DistributedTracePayloadImpl(com.newrelic.agent.tracing.DistributedTracePayloadImpl) Transaction(com.newrelic.agent.Transaction) DatastoreConfig(com.newrelic.agent.config.DatastoreConfig) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DistributedTracingConfig (com.newrelic.agent.config.DistributedTracingConfig)10 AgentConfig (com.newrelic.agent.config.AgentConfig)3 DistributedTraceService (com.newrelic.agent.tracing.DistributedTraceService)3 TransactionStats (com.newrelic.agent.stats.TransactionStats)2 DistributedTracePayloadImpl (com.newrelic.agent.tracing.DistributedTracePayloadImpl)2 HashMap (java.util.HashMap)2 Transaction (com.newrelic.agent.Transaction)1 CrossProcessConfig (com.newrelic.agent.config.CrossProcessConfig)1 DatastoreConfig (com.newrelic.agent.config.DatastoreConfig)1 TransactionTracerConfig (com.newrelic.agent.config.TransactionTracerConfig)1 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)1 ResponseTimeStats (com.newrelic.agent.stats.ResponseTimeStats)1 SimpleStatsEngine (com.newrelic.agent.stats.SimpleStatsEngine)1 SpanProxy (com.newrelic.agent.tracing.SpanProxy)1 W3CTraceStateHeader (com.newrelic.agent.tracing.W3CTraceStateHeader)1 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)1 TransactionCounts (com.newrelic.agent.transaction.TransactionCounts)1 TransactionThrowable (com.newrelic.agent.transaction.TransactionThrowable)1 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)1 InboundHeaders (com.newrelic.api.agent.InboundHeaders)1