use of com.newrelic.agent.tracers.OtherRootTracer 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.OtherRootTracer in project newrelic-java-agent by newrelic.
the class TransactionStateImpl method getTracer.
/**
* Get tracer for weaved code and XML instrumentation (no tracer factory)
*/
@Override
public Tracer getTracer(Transaction tx, final Object invocationTarget, final ClassMethodSignature sig, final String metricName, final int flags) {
TransactionActivity activity = tx.getTransactionActivity();
if (tx.isIgnore() || activity.isTracerStartLocked()) {
return null;
}
Tracer tracer;
final MetricNameFormat mnf = MetricNameFormats.getFormatter(invocationTarget, sig, metricName, flags);
if (TracerFlags.isDispatcher(flags)) {
tracer = new OtherRootTracer(tx, sig, invocationTarget, mnf);
} else {
tracer = new DefaultTracer(tx, sig, invocationTarget, mnf, flags);
}
return tracerStarted(tx, sig, tracer);
}
use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class InstrumentationImpl method startTracer.
// Preconditions are met: start a new tracer on this thread. There may not be a Transaction on this thread. Code
// in this path MUST NOT attempt to touch the Transaction or do anything that might bring one into existence. This
// inconvenience is absolutely critical to the performance of our async instrumentation.
private Tracer startTracer(TransactionActivity txa, Object target, int signatureId, String metricName, int flags) {
ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
MetricNameFormat mnf = MetricNameFormats.getFormatter(target, sig, metricName, flags);
Tracer tracer;
if (TracerFlags.isRoot(flags)) {
// Dispatcher || Async
tracer = new OtherRootTracer(txa, sig, target, mnf, flags, System.nanoTime());
} else {
tracer = new DefaultTracer(txa, sig, target, mnf, flags);
}
txa.tracerStarted(tracer);
return tracer;
}
use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class TransactionTest method createDispatcherTracer.
// Create a Tracer for tests that require one.
private Tracer createDispatcherTracer(boolean createRequest) {
Transaction tx = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
if (createRequest) {
MockHttpRequest httpRequest = new MockHttpRequest();
MockHttpResponse httpResponse = new MockHttpResponse();
return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
} else {
return new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("thisismyname"));
}
}
use of com.newrelic.agent.tracers.OtherRootTracer in project newrelic-java-agent by newrelic.
the class SegmentTest method makeTransaction.
/**
* Creates a transaction with one tracer and returns the root tracer (unfinished).
*/
private static Tracer makeTransaction() {
Transaction tx = Transaction.getTransaction(true);
TransactionActivity txa = TransactionActivity.get();
Assert.assertNotNull(txa);
Tracer root = new OtherRootTracer(tx, new ClassMethodSignature("com.newrelic.agent.SegmentTest", "makeTransaction", "()V"), null, DefaultTracer.NULL_METRIC_NAME_FORMATTER);
txa.tracerStarted(root);
tx.setTransactionName(TransactionNamePriority.FRAMEWORK_HIGH, true, "FOO", "BAR", "BAZ");
return root;
}
Aggregations