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);
}
}
}
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;
}
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;
}
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;
}
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);
}
Aggregations