Search in sources :

Example 1 with OtherRootTracer

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;
}
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 2 with OtherRootTracer

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);
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) 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) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 3 with OtherRootTracer

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;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 4 with OtherRootTracer

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"));
    }
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 5 with OtherRootTracer

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;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Aggregations

OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)51 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)45 Transaction (com.newrelic.agent.Transaction)35 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)34 Test (org.junit.Test)31 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)15 Tracer (com.newrelic.agent.tracers.Tracer)15 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)11 Response (com.newrelic.api.agent.Response)10 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)9 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)8 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)8 Request (com.newrelic.api.agent.Request)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)8 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)8 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)8 TransactionDataList (com.newrelic.agent.TransactionDataList)6