Search in sources :

Example 1 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class Transaction method requestDestroyed.

public void requestDestroyed() {
    Agent.LOG.log(Level.FINEST, "Request destroyed");
    synchronized (requestStateChangeLock) {
        ServiceFactory.getStatsService().doStatsWork(StatsWorks.getIncrementCounterWork(MetricNames.SUPPORTABILITY_TRANSACTION_REQUEST_DESTROYED, 1), MetricNames.SUPPORTABILITY_TRANSACTION_REQUEST_DESTROYED);
        if (!this.isInProgress()) {
            return;
        }
        Tracer rootTracer = getTransactionActivity().getRootTracer();
        Tracer lastTracer = getTransactionActivity().getLastTracer();
        if (lastTracer != null && rootTracer == lastTracer) {
            Transaction currentTxn = getTransaction(false);
            if (currentTxn != null) {
                currentTxn.addOutboundResponseHeaders();
                lastTracer.finish(Opcodes.RETURN, null);
            }
        } else {
            Agent.LOG.log(Level.FINER, "Inconsistent state!  tracer != last tracer for {0} ({1} != {2})", this, rootTracer, lastTracer);
        }
    }
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 2 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class Transaction method getToken.

/**
 * This should be the only place that increments the counter.
 */
public Token getToken() {
    if (ServiceFactory.getServiceManager().getCircuitBreakerService().isTripped()) {
        Agent.LOG.log(Level.FINER, "Transaction {0}: cannot create token, circuit breaker is tripped.", this);
        return NoOpToken.INSTANCE;
    } else if (isIgnore()) {
        Agent.LOG.log(Level.FINER, "Transaction {0}: cannot create token, transaction is ignored.", this);
        return NoOpToken.INSTANCE;
    } else if (!isStarted()) {
        Agent.LOG.log(Level.FINER, "Transaction {0}: cannot create token, transaction not started.", this);
        return NoOpToken.INSTANCE;
    }
    Tracer parent = getTransactionActivity().getLastTracer();
    if (parent == null || parent.isLeaf()) {
        // If we don't have a parent tracer or the parent is a leaf node, we don't want to allow Token creation
        Agent.LOG.log(Level.FINER, "Transaction {0}: cannot create token, no last tracer on {1}.", this, getTransactionActivity());
        return NoOpToken.INSTANCE;
    }
    if (counts.isOverTokenLimit()) {
        Agent.LOG.log(Level.FINER, "Transaction {0}: async token limit {1} exceeded. Ignoring all further async activity", this, counts.getMaxTokens());
        return NoOpToken.INSTANCE;
    }
    TokenImpl token = null;
    boolean wasAdded = false;
    synchronized (lock) {
        if (!isFinished()) {
            token = new TokenImpl(parent);
            activeCount.incrementAndGet();
            counts.getToken();
            TimedSet<TokenImpl> tokenCache = activeTokensCache.get();
            if (tokenCache == null) {
                activeTokensCache.compareAndSet(null, new TimedTokenSet(ASYNC_TIMEOUT_SECONDS(), TimeUnit.SECONDS, ServiceFactory.getExpirationService()));
                tokenCache = activeTokensCache.get();
            }
            tokenCache.put(token);
            wasAdded = true;
        }
    }
    if (wasAdded) {
        Agent.LOG.log(Level.FINEST, "Transaction {0}: created active token {1}", this, token);
    } else {
        Agent.LOG.log(Level.FINER, "Transaction {0}: already finished. cannot create token", this);
        // transaction finishes before that block executes isFinished() resulting in a null token returned below
        return NoOpToken.INSTANCE;
    }
    // Record Token API usage supportability metric
    getMetricAggregator().incrementCounter(AgentBridge.currentApiSource.get().getSupportabilityMetric(MetricNames.SUPPORTABILITY_API_TOKEN));
    return token;
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 3 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class Transaction method startSegment.

/**
 * Internal implementation of {@link com.newrelic.agent.bridge.Transaction#createAndStartTracedActivity()} . This
 * has to happen inside the transaction class because it requires updates to an async map (runningChildren)
 */
public Segment startSegment(String category, String segmentName) {
    if (counts.isOverTracerSegmentLimit() || ServiceFactory.getServiceManager().getCircuitBreakerService().isTripped() || isIgnore()) {
        return null;
    }
    Tracer parent = getTransactionActivity().getLastTracer();
    if (parent == null || parent.isLeaf()) {
        // If we don't have a parent tracer or the parent is a leaf node, we don't want to allow a Segment
        Agent.LOG.log(Level.FINER, "Transaction {0}: cannot create event, no last tracer on {1}", this, getTransactionActivity());
        return null;
    }
    // async_context will be set to the name of the thread that finishes this TracedActivity
    TransactionActivity txa = TransactionActivity.createWithoutHolder(this, nextActivityId.getAndIncrement(), SEGMENT_TXA_DEFAULT_ASYNC_CONTEXT);
    ClassMethodSignature cms = new ClassMethodSignature(segmentName, "", "");
    Tracer tracer = new OtherRootTracer(txa, cms, SEGMENT_INVOKER, SEGMENT_URI);
    tracer.setMetricName(category, segmentName);
    AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
    if (tokenAndRefCount != null) {
        parent = (Tracer) tokenAndRefCount.tracedMethod.getAndSet(tracer);
    }
    Segment segment = new Segment(parent, tracer);
    txa.setSegment(segment);
    tracer.setParentTracer(parent);
    txa.tracerStarted(tracer);
    Agent.LOG.log(Level.FINEST, "Transaction {0}: startSegment(): {1} created and started with tracer {2}", this, segment, tracer);
    // Record Segment API usage supportability metric
    getMetricAggregator().incrementCounter(AgentBridge.currentApiSource.get().getSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SEGMENT));
    return segment;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) ExitTracer(com.newrelic.agent.bridge.ExitTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) AgentBridge(com.newrelic.agent.bridge.AgentBridge) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 4 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionApiImpl method getTracedMethod.

@Override
public TracedMethod getTracedMethod() {
    Transaction tx = getTransactionIfExists();
    Tracer tracedMethod = getTracedMethodTracer(tx);
    if (tracedMethod == null) {
        return NoOpTracedMethod.INSTANCE;
    }
    return tracedMethod;
}
Also used : NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) Tracer(com.newrelic.agent.tracers.Tracer)

Example 5 with Tracer

use of com.newrelic.agent.tracers.Tracer in project newrelic-java-agent by newrelic.

the class TransactionStateImpl method getTracer.

@Override
public Tracer getTracer(Transaction tx, TracerFactory tracerFactory, ClassMethodSignature sig, Object obj, Object... args) {
    TransactionActivity activity = tx.getTransactionActivity();
    if (tx.isIgnore() || activity.isTracerStartLocked()) {
        return null;
    }
    Tracer tracer = tracerFactory.getTracer(tx, sig, obj, args);
    return tracerStarted(tx, sig, tracer);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SkipTracer(com.newrelic.agent.tracers.SkipTracer)

Aggregations

Tracer (com.newrelic.agent.tracers.Tracer)263 Test (org.junit.Test)195 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)104 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)99 Transaction (com.newrelic.agent.Transaction)86 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)54 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)41 ExitTracer (com.newrelic.agent.bridge.ExitTracer)39 TokenImpl (com.newrelic.agent.TokenImpl)35 StartAndThenLink (com.newrelic.agent.TransactionAsyncUtility.StartAndThenLink)31 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)25 TransactionData (com.newrelic.agent.TransactionData)24 HashMap (java.util.HashMap)24 SqlTracer (com.newrelic.agent.tracers.SqlTracer)20 ArrayList (java.util.ArrayList)19 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)17 TransactionStats (com.newrelic.agent.stats.TransactionStats)16 MockRPMService (com.newrelic.agent.MockRPMService)15 JSONArray (org.json.simple.JSONArray)15 JSONObject (org.json.simple.JSONObject)14