Search in sources :

Example 1 with TransactionTracerConfig

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

the class Transaction method finishTransaction.

private void finishTransaction() {
    try {
        synchronized (lock) {
            // this may have the side-effect of ignoring the transaction
            freezeTransactionName();
            if (ignore) {
                Agent.LOG.log(Level.FINER, "Transaction {0} was cancelled: ignored. This is not an error condition.", this);
                ServiceFactory.getTransactionService().transactionCancelled(this);
                return;
            }
            if (finishedChildren.isEmpty()) {
                Agent.LOG.log(Level.FINER, "Transaction {0} was cancelled: no activities. This is not an error condition.", this);
                ServiceFactory.getTransactionService().transactionCancelled(this);
                return;
            }
            // this needs to go before dispatcher.transactionFinished so that all of
            // the time metrics are correct
            TransactionStats transactionStats = transactionFinishedActivityMerging();
            transactionTime.markTransactionAsDone();
            recordFinalGCTime(transactionStats);
            handleTokenTimeout(transactionStats);
            String txName = priorityTransactionName.getName();
            // parse headers in dispatcher request before we get rid of request/response objects
            getInboundHeaderState();
            // this may trigger this dispatcher to record extra metrics like apdex & HttpDispatcher
            dispatcher.transactionFinished(txName, transactionStats);
            if (Agent.LOG.isFinerEnabled()) {
                String requestURI = dispatcher == null ? "No Dispatcher Defined" : dispatcher.getUri();
                Agent.LOG.log(Level.FINER, "Transaction {0} for request: {1} finished {2}ms {3}", txName, requestURI, transactionTime.getResponseTimeInMilliseconds(), this);
            }
            if (!ServiceFactory.getServiceManager().isStarted()) {
                Agent.LOG.log(Level.INFO, "Transaction {0} tried to finish but ServiceManager not started", this);
                return;
            }
            // Some parts of the code below are only required if this transaction's TT is selected
            // for sending upstream. Unfortunately we don't know at this point in the harvest whether
            // this transaction's trace will be selected, and there's no obvious way to know that can
            // be built with maintainable code. There was a previous effort at this, but the obvious
            // happened: it sat broken in the code (i.e. it did some checks, but always returned true)
            // for 18 months before we noticed and ripped it out. Please don't repeat this mistake.
            TransactionTracerConfig ttConfig = getTransactionTracerConfig();
            TransactionCounts rootCounts = getTransactionCounts();
            if (rootCounts.isOverTracerSegmentLimit()) {
                getIntrinsicAttributes().put(AttributeNames.SEGMENT_CLAMP, rootCounts.getSegmentCount());
                // Record supportability metric to track when a segment clamp occurs
                transactionStats.getUnscopedStats().getStats(MetricNames.SUPPORTABILITY_TRANSACTION_SEGMENT_CLAMP).recordDataPoint(rootCounts.getSegmentCount());
            }
            if (rootCounts.isOverTransactionSize()) {
                getIntrinsicAttributes().put(AttributeNames.SIZE_LIMIT_PARAMETER_NAME, "The transaction size limit was reached");
            }
            int count = rootCounts.getStackTraceCount();
            if (count >= ttConfig.getMaxStackTraces()) {
                getIntrinsicAttributes().put(AttributeNames.STACK_TRACE_CLAMP, count);
            }
            if (rootCounts.isOverTokenLimit()) {
                getIntrinsicAttributes().put(AttributeNames.TOKEN_CLAMP, rootCounts.getTokenCount());
            }
            count = rootCounts.getExplainPlanCount();
            if (count >= ttConfig.getMaxExplainPlans()) {
                getIntrinsicAttributes().put(AttributeNames.EXPLAIN_PLAN_CLAMP, count);
            }
            DistributedTracingConfig distributedTracingConfig = getAgentConfig().getDistributedTracingConfig();
            if (!distributedTracingConfig.isEnabled()) {
                if (getInboundHeaderState().isTrustedCatRequest()) {
                    String id = getInboundHeaderState().getClientCrossProcessId();
                    getIntrinsicAttributes().put(AttributeNames.CLIENT_CROSS_PROCESS_ID_PARAMETER_NAME, id);
                }
                String referrerGuid = getInboundHeaderState().getReferrerGuid();
                if (referrerGuid != null) {
                    getIntrinsicAttributes().put(AttributeNames.REFERRING_TRANSACTION_TRACE_ID_PARAMETER_NAME, referrerGuid);
                }
                String tripId = getCrossProcessTransactionState().getTripId();
                if (tripId != null) {
                    getIntrinsicAttributes().put(AttributeNames.TRIP_ID_PARAMETER_NAME, tripId);
                    int pathHash = getCrossProcessTransactionState().generatePathHash();
                    getIntrinsicAttributes().put(AttributeNames.PATH_HASH_PARAMETER_NAME, ServiceUtils.intToHexString(pathHash));
                }
            }
            if (isSynthetic()) {
                Agent.LOG.log(Level.FINEST, "Completing Synthetics transaction for monitor {0}", getInboundHeaderState().getSyntheticsMonitorId());
                getIntrinsicAttributes().put(AttributeNames.SYNTHETICS_RESOURCE_ID, this.getInboundHeaderState().getSyntheticsResourceId());
                getIntrinsicAttributes().put(AttributeNames.SYNTHETICS_MONITOR_ID, this.getInboundHeaderState().getSyntheticsMonitorId());
                getIntrinsicAttributes().put(AttributeNames.SYNTHETICS_JOB_ID, this.getInboundHeaderState().getSyntheticsJobId());
            }
            if (timeoutCause != null && timeoutCause.cause != null) {
                getIntrinsicAttributes().put(AttributeNames.TIMEOUT_CAUSE, timeoutCause.cause);
            }
            String displayHost = getAgentConfig().getValue("process_host.display_name", null);
            if (displayHost != null) {
                getAgentAttributes().put(AttributeNames.DISPLAY_HOST, displayHost);
            }
            String instanceName = ServiceFactory.getEnvironmentService().getEnvironment().getAgentIdentity().getInstanceName();
            if (instanceName != null) {
                getAgentAttributes().put(AttributeNames.INSTANCE_NAME, instanceName);
            }
            // Only add jvm.thread_name if transaction  was not timed out and
            // if it's *NOT* a multi-threaded transaction
            TimedSet<TokenImpl> tokenCache = activeTokensCache.get();
            if ((tokenCache == null || tokenCache.timedOutCount() == 0) && finishedChildren.size() == 1) {
                if (!ServiceFactory.getThreadService().isAgentThreadId(Thread.currentThread().getId())) {
                    getAgentAttributes().put(AttributeNames.THREAD_NAME, Thread.currentThread().getName());
                }
            }
            getIntrinsicAttributes().put(AttributeNames.PRIORITY, getPriority());
            TransactionData transactionData = new TransactionData(this, rootCounts.getTransactionSize());
            ServiceFactory.getTransactionService().transactionFinished(transactionData, transactionStats);
        }
    } catch (Throwable th) {
        Agent.LOG.log(Level.WARNING, th, "Transaction {0} was not reported because of an internal error.", this);
        ServiceFactory.getTransactionService().transactionCancelled(this);
    }
}
Also used : DistributedTracingConfig(com.newrelic.agent.config.DistributedTracingConfig) TransactionStats(com.newrelic.agent.stats.TransactionStats) TransactionThrowable(com.newrelic.agent.transaction.TransactionThrowable) TransactionCounts(com.newrelic.agent.transaction.TransactionCounts) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig)

Example 2 with TransactionTracerConfig

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

the class DefaultSqlTracer method doFinish.

@Override
protected void doFinish(int opcode, Object returnValue) {
    super.doFinish(opcode, returnValue);
    Transaction transaction = getTransaction();
    if (transaction != null) {
        TransactionTracerConfig transactionTracerConfig = transaction.getTransactionTracerConfig();
        double explainThresholdInNanos = transactionTracerConfig.getExplainThresholdInNanos();
        // The string equality check here is intentional, both values are interned Strings
        if (SqlObfuscator.RAW_SETTING == transactionTracerConfig.getRecordSql() || getDuration() > explainThresholdInNanos) {
            // we have to copy the parameters because they will be cleared later
            Object[] sqlParameters = params == null ? null : new Object[params.length];
            if (sqlParameters != null) {
                System.arraycopy(params, 0, sqlParameters, 0, params.length);
                params = sqlParameters;
            }
        }
        if (isTransactionSegment() && captureSql()) {
            this.sqlObject = getSql();
        }
        parseStatement(returnValue, transaction.getRPMService().getConnectionTimestamp());
        if (isTransactionSegment() && sql != null) {
            if (transactionTracerConfig.isExplainEnabled()) {
                captureExplain(parsedDatabaseStatement, explainThresholdInNanos, transactionTracerConfig);
            } else {
                if (Agent.isDebugEnabled()) {
                    String msg = MessageFormat.format("Statement exceeded threshold?: {0}", getDuration() > explainThresholdInNanos);
                    Agent.LOG.finer(msg);
                }
            }
        }
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig)

Example 3 with TransactionTracerConfig

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

the class DefaultTracer method attemptToStoreStackTrace.

private void attemptToStoreStackTrace() {
    if (getTransaction() != null && shouldStoreStackTrace()) {
        TransactionTracerConfig transactionTracerConfig = getTransaction().getTransactionTracerConfig();
        double stackTraceThresholdInNanos = transactionTracerConfig.getStackTraceThresholdInNanos();
        int stackTraceMax = transactionTracerConfig.getMaxStackTraces();
        // count
        if ((getDuration() > stackTraceThresholdInNanos) && (childHasStackTrace || (getTransaction().getTransactionCounts().getStackTraceCount() < stackTraceMax))) {
            storeStackTrace();
            // only increment the stack trace count if there are no children which have taken a stack trace
            if (!childHasStackTrace) {
                getTransaction().getTransactionCounts().incrementStackTraceCount();
                // this property is used to tell parents not to increment the stack trace count
                childHasStackTrace = true;
            }
        }
    }
}
Also used : TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig)

Example 4 with TransactionTracerConfig

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

the class TransactionDataTest method getTransactionTracerConfig.

@Test
public void getTransactionTracerConfig() {
    TransactionData txd = getTxData(tx);
    Assert.assertNull(txd.getTransactionTracerConfig());
    AgentConfig mock = Mockito.mock(AgentConfig.class);
    Mockito.when(tx.getAgentConfig()).thenReturn(mock);
    TransactionTracerConfig expected = Mockito.mock(TransactionTracerConfig.class);
    Mockito.when(tx.getAgentConfig().getTransactionTracerConfig()).thenReturn(expected);
    txd = getTxData(tx);
    TransactionTracerConfig result = txd.getTransactionTracerConfig();
    Assert.assertSame(expected, result);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) Test(org.junit.Test)

Example 5 with TransactionTracerConfig

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

the class TransactionTraceTest method setUp.

private void setUp(boolean isCaptureAtts, boolean captureRequestAtts, boolean requestUri, boolean simpleCompression) throws Exception {
    iAgentConfig = mock(AgentConfig.class);
    TransactionTracerConfig transTracerConfig = mock(TransactionTracerConfig.class);
    when(iAgentConfig.getTransactionTracerConfig()).thenReturn(transTracerConfig);
    when(iAgentConfig.isSimpleCompression()).thenReturn(simpleCompression);
    MockServiceManager manager = new MockServiceManager();
    ServiceFactory.setServiceManager(manager);
    ImmutableMap<String, Object> distributedTracingSettings = ImmutableMap.<String, Object>builder().put(DistributedTracingConfig.ENABLED, Boolean.FALSE).build();
    Map<String, Object> settings = new HashMap<>();
    settings.put(AgentConfigImpl.DISTRIBUTED_TRACING, distributedTracingSettings);
    setConfigAttributes(settings, isCaptureAtts, captureRequestAtts, requestUri, simpleCompression);
    ConfigService cService = new MockConfigService(AgentConfigImpl.createAgentConfig(settings));
    manager.setConfigService(cService);
    manager.setTransactionTraceService(new TransactionTraceService());
    manager.setTransactionService(new TransactionService());
    manager.setAttributesService(new AttributesService());
}
Also used : TransactionService(com.newrelic.agent.TransactionService) HashMap(java.util.HashMap) AttributesService(com.newrelic.agent.attributes.AttributesService) MockConfigService(com.newrelic.agent.MockConfigService) AgentConfig(com.newrelic.agent.config.AgentConfig) MockConfigService(com.newrelic.agent.MockConfigService) ConfigService(com.newrelic.agent.config.ConfigService) MockServiceManager(com.newrelic.agent.MockServiceManager) JSONObject(org.json.simple.JSONObject) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig)

Aggregations

TransactionTracerConfig (com.newrelic.agent.config.TransactionTracerConfig)19 SqlObfuscator (com.newrelic.agent.database.SqlObfuscator)9 Test (org.junit.Test)9 TransactionSegment (com.newrelic.agent.trace.TransactionSegment)8 JSONArray (org.json.simple.JSONArray)6 AgentConfig (com.newrelic.agent.config.AgentConfig)5 JSONObject (org.json.simple.JSONObject)5 Transaction (com.newrelic.agent.Transaction)4 TransactionStats (com.newrelic.agent.stats.TransactionStats)3 MockDispatcher (com.newrelic.agent.MockDispatcher)2 MockDispatcherTracer (com.newrelic.agent.MockDispatcherTracer)2 TransactionActivity (com.newrelic.agent.TransactionActivity)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MockConfigService (com.newrelic.agent.MockConfigService)1 MockServiceManager (com.newrelic.agent.MockServiceManager)1 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)1 TransactionService (com.newrelic.agent.TransactionService)1 AttributesService (com.newrelic.agent.attributes.AttributesService)1 RecordSql (com.newrelic.agent.bridge.datastore.RecordSql)1 ConfigService (com.newrelic.agent.config.ConfigService)1