Search in sources :

Example 1 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature 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 ClassMethodSignature

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

the class InstrumentationImpl method oldCreateSqlTracer.

// This code path is similar to the 3.16.1 and earlier tracer creation path. It is retained for use by legacy
// async instrumentation, including NAPS (Netty, Akka, Play, Scala) and async servlet instrumentation.
private ExitTracer oldCreateSqlTracer(TransactionActivity txa, Object invocationTarget, int signatureId, String metricName, int flags) {
    if (txa == null) {
        AgentBridge.TokenAndRefCount tokenAndRefCount = AgentBridge.activeToken.get();
        if (tokenAndRefCount != null && tokenAndRefCount.token != null) {
            // Fast path for scala instrumentation (and potentially others in the future)
            Transaction tx = Transaction.getTransaction(false);
            if (tx == null) {
                if (tokenAndRefCount.token.getTransaction() instanceof Transaction) {
                    tx = (Transaction) tokenAndRefCount.token.getTransaction();
                } else {
                    return null;
                }
            }
            txa = TransactionActivity.create(tx, Integer.MAX_VALUE);
            flags = flags | TracerFlags.ASYNC;
            ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
            MetricNameFormat mnf = MetricNameFormats.getFormatter(invocationTarget, sig, metricName, flags);
            Tracer tracer;
            if (TracerFlags.isRoot(flags)) {
                // Dispatcher || Async
                tracer = new OtherRootSqlTracer(txa, sig, invocationTarget, mnf, flags);
            } else if (overSegmentLimit(txa)) {
                logger.log(Level.FINEST, "Transaction has exceeded tracer segment limit. Returning ultralight sql tracer.");
                return UltraLightTracer.createClampedSegment(txa, sig);
            } else {
                tracer = new DefaultSqlTracer(txa, sig, invocationTarget, mnf, flags);
            }
            txa.tracerStarted(tracer);
            Tracer initiatingTracer = (Tracer) tokenAndRefCount.tracedMethod.getAndSet(tracer);
            tx.startFastAsyncWork(txa, initiatingTracer);
            return tracer;
        } else if (TracerFlags.isAsync(flags)) {
            txa = TransactionActivity.create(null, Integer.MAX_VALUE);
            return startTracer(txa, invocationTarget, signatureId, metricName, flags);
        }
    }
    // Avoid creating tracers for NoOpTransaction, etc.
    com.newrelic.agent.Transaction transaction = com.newrelic.agent.Transaction.getTransaction(TracerFlags.isDispatcher(flags));
    if (transaction == null) {
        return null;
    }
    try {
        if (!TracerFlags.isDispatcher(flags) && !transaction.isStarted()) {
            // if we're not in a transaction and this isn't a dispatcher tracer, bail before we create objects
            return null;
        }
        if (transaction.getTransactionActivity().isLeaf()) {
            return null;
        }
        ClassMethodSignature sig = ClassMethodSignatures.get().get(signatureId);
        return transaction.getTransactionState().getSqlTracer(transaction, invocationTarget, sig, metricName, flags);
    } catch (Throwable t) {
        logger.log(Level.FINEST, t, "createTracer({0}, {1}, {2}, {3})", invocationTarget, signatureId, metricName, flags);
        return null;
    }
}
Also used : Transaction(com.newrelic.agent.Transaction) NoOpTransaction(com.newrelic.agent.bridge.NoOpTransaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) 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) AgentBridge(com.newrelic.agent.bridge.AgentBridge) Transaction(com.newrelic.agent.Transaction) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) DefaultSqlTracer(com.newrelic.agent.tracers.DefaultSqlTracer)

Example 3 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature 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 ClassMethodSignature

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

the class AgentWrapper method invoke.

/**
 * @see ReflectionStyleClassMethodAdapter
 */
public static ExitTracer invoke(PointCutInvocationHandler invocationHandler, String className, String methodName, String methodDesc, Object invocationTarget, Object[] args) {
    ClassMethodSignature classMethodSig = new ClassMethodSignature(className, methodName, methodDesc);
    if (invocationHandler instanceof EntryInvocationHandler) {
        EntryInvocationHandler handler = (EntryInvocationHandler) invocationHandler;
        handler.handleInvocation(classMethodSig, invocationTarget, args);
        return null;
    } else if (invocationHandler instanceof TracerFactory) {
        return ServiceFactory.getTracerService().getTracer((TracerFactory) invocationHandler, classMethodSig, invocationTarget, args);
    }
    return null;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) TracerFactory(com.newrelic.agent.tracers.TracerFactory) EntryInvocationHandler(com.newrelic.agent.tracers.EntryInvocationHandler)

Example 5 with ClassMethodSignature

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

the class ProfiledMethodFactory method getProfiledMethod.

public ProfiledMethod getProfiledMethod(Tracer tracer) {
    ClassMethodSignature methodSignature = tracer.getClassMethodSignature();
    ProfiledMethod method = getTracerMethods().get(methodSignature);
    if (method == null) {
        StackTraceElement stackTraceElement = new StackTraceElement(methodSignature.getClassName(), methodSignature.getMethodName(), null, -1);
        method = ProfiledMethod.newProfiledMethod(getNextMethodId(), profile, stackTraceElement);
        if (method != null) {
            ProfiledMethod previous = getTracerMethods().putIfAbsent(methodSignature, method);
            if (null != previous) {
                method = previous;
            } else {
                MethodInfo methodInfo = getMethodInfo(methodSignature);
                method.setMethodInfo(methodInfo);
            }
        }
    }
    return method;
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) ExactMethodInfo(com.newrelic.agent.profile.method.ExactMethodInfo) MethodInfo(com.newrelic.agent.profile.method.MethodInfo)

Aggregations

ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)112 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)69 Transaction (com.newrelic.agent.Transaction)60 Test (org.junit.Test)55 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)46 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)44 Tracer (com.newrelic.agent.tracers.Tracer)41 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)26 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)23 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 HashMap (java.util.HashMap)17 TransactionData (com.newrelic.agent.TransactionData)16 JSONObject (org.json.simple.JSONObject)15 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)13 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)12 JSONArray (org.json.simple.JSONArray)11 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)10 Response (com.newrelic.api.agent.Response)10 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)9