use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.
the class CallbackRunnable_Instrumentation method value_$eq.
/**
* Override the setter for "value" so we can replace it with our wrapped version
*/
public void value_$eq(Try<T> original) {
Weaver.callOriginal();
AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
if (tokenAndRefCount == null) {
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (tx != null) {
AgentBridge.TokenAndRefCount tokenAndRef = new AgentBridge.TokenAndRefCount(tx.getToken(), AgentBridge.getAgent().getTracedMethod(), new AtomicInteger(1));
value = new WrappedTry<>(value, tokenAndRef);
}
} else {
value = new WrappedTry<>(value, tokenAndRefCount);
tokenAndRefCount.refCount.incrementAndGet();
}
}
use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.
the class FutureInnerClass_Instrumentation method apply.
public <T> scala.concurrent.Future<T> apply(Function0<T> body, final ExecutionContext executor) {
AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
if (tokenAndRefCount == null) {
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (tx != null && (!body.getClass().getName().startsWith("akka."))) {
AgentBridge.TokenAndRefCount tokenAndRef = new AgentBridge.TokenAndRefCount(tx.getToken(), AgentBridge.getAgent().getTracedMethod(), new AtomicInteger(1));
body = new WrappedFunction0(body, tokenAndRef);
}
} else {
body = new WrappedFunction0(body, tokenAndRefCount);
tokenAndRefCount.refCount.incrementAndGet();
}
scala.concurrent.Future<T> value = Weaver.callOriginal();
return value;
}
use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.
the class Transformation_Instrumentation method run.
@Trace(excludeFromTransactionTrace = true)
public void run() {
Segment segment = null;
boolean remove = false;
if (tokenAndRefCount != null) {
// If we are here and there is no activeToken in progress we are the first one so we set this boolean in
// order to correctly remove the "activeToken" from the thread local after the original run() method executes
remove = AgentBridge.activeToken.get() == null;
AgentBridge.activeToken.set(tokenAndRefCount);
// getTransaction implicitly makes Transaction available on Thread to runnable
Transaction tx = AgentBridge.getAgent().getTransaction(false);
if (scalaFuturesAsSegments && remove) {
if (tx != null) {
segment = tx.startSegment("Scala", "Callback");
segment.setMetricName("Scala", "Callback", ScalaUtils.nameScalaFunction(_arg.getClass().getName()));
}
}
}
try {
Weaver.callOriginal();
} finally {
if (tokenAndRefCount != null) {
if (segment != null) {
segment.end();
}
if (remove) {
AgentBridge.activeToken.remove();
}
if (tokenAndRefCount.refCount.decrementAndGet() == 0) {
tokenAndRefCount.token.expire();
tokenAndRefCount.token = null;
}
}
}
}
use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.
the class AgentImpl method getTracedMethod.
/**
* If in a transaction, then getTransaction().getTracedMethod() returns the same thing as this method. If outside a
* transaction then this method returns a noop. Note: The getTransaction().getTracedMethod() will return null.
*/
@Override
public TracedMethod getTracedMethod() {
com.newrelic.agent.bridge.Transaction transaction = getTransaction(false);
if (NoOpTransaction.INSTANCE.equals(transaction)) {
return NoOpTracedMethod.INSTANCE;
}
com.newrelic.agent.Transaction txn = com.newrelic.agent.Transaction.getTransaction(false);
// TransactionApiImpl to ensure the same behavior.
if (txn == null) {
return NoOpTracedMethod.INSTANCE;
}
TransactionActivity txa = txn.getTransactionActivity();
if (txa == null) {
return NoOpTracedMethod.INSTANCE;
}
Tracer tracer = txa.getLastTracer();
return (tracer == null) ? NoOpTracedMethod.INSTANCE : tracer;
}
use of com.newrelic.agent.bridge.Transaction in project newrelic-java-agent by newrelic.
the class Cell_Instrumentation method sendMessage.
@Trace
public void sendMessage(Envelope_Instrumentation envelope) {
String receiver = props().actorClass().getName();
String messageClassName = envelope.message().getClass().getName();
Transaction transaction = AgentBridge.getAgent().getTransaction(false);
if (transaction != null && transaction.isStarted() && !AkkaUtil.isHeartBeatMessage(messageClassName) && !AkkaUtil.isLogger(receiver) && !AkkaUtil.isAkkaStream(messageClassName)) {
String sender = AkkaUtil.getActor(envelope.sender());
AkkaUtil.recordTellMetric(receiver, sender, messageClassName);
if (envelope.token != null) {
// Akka may migrate envelopes to another ActorCell.
// See UnstartedCell in RepointableActorRef.scala.
// We expire and replace the existing token just to be on the safe side.
envelope.token.expire();
// this prevents the warning even though it's immediately reassigned
envelope.token = null;
}
envelope.token = transaction.getToken();
}
Weaver.callOriginal();
}
Aggregations