Search in sources :

Example 1 with TracerFactory

use of com.newrelic.agent.tracers.TracerFactory 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 2 with TracerFactory

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

the class TransactionStateImplTest method tracerGeneration_segmentClampInPlace_afterRoot.

@Test
public void tracerGeneration_segmentClampInPlace_afterRoot() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TransactionCounts transactionCounts = tx.getTransactionCounts();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    transactionCounts.addTracers(3001);
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude1", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, null, sig, null, simpleFlags);
    assertNotEquals(UltraLightTracer.class, tracer.getClass());
    assertEquals("Java/com.test.Dude/dude1", tracer.getTransactionSegmentName());
    Tracer sqlTracer = tx.getTransactionState().getSqlTracer(tx, null, sig, null, simpleFlags);
    assertEquals(UltraLightTracer.class, sqlTracer.getClass());
    assertEquals("Clamped/com.test.Dude/dude1", sqlTracer.getTransactionSegmentName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TransactionCounts(com.newrelic.agent.transaction.TransactionCounts) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Example 3 with TracerFactory

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

the class TransactionStateImplTest method tracerMetricName_Null.

@Test
public void tracerMetricName_Null() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude1", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, null, sig, null, simpleFlags);
    assertEquals(tracer, tx.getTransactionActivity().getLastTracer());
    assertEquals("Java/com.test.Dude/dude1", tracer.getMetricName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Example 4 with TracerFactory

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

the class TransactionStateImplTest method tracerMetricName.

@Test
public void tracerMetricName() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude4", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, new Object(), sig, "Test/${className}/dude4", TracerFlags.CUSTOM);
    assertEquals(tracer, tx.getTransactionActivity().getLastTracer());
    assertEquals("Test/java.lang.Object/dude4", tracer.getMetricName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Example 5 with TracerFactory

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

the class TransactionStateImplTest method tracerMetricName_NullInvocationTarget.

@Test
public void tracerMetricName_NullInvocationTarget() throws Exception {
    Tracer rootTracer = createRootTracer();
    Transaction tx = Transaction.getTransaction();
    TracerFactory tracerFactory = Mockito.mock(TracerFactory.class, new Returns(rootTracer));
    tx.getTransactionState().getTracer(tx, tracerFactory, null, null, (Object[]) null);
    assertEquals(rootTracer, tx.getTransactionActivity().getRootTracer());
    ClassMethodSignature sig = new ClassMethodSignature("com.test.Dude", "dude3", "()V");
    Tracer tracer = tx.getTransactionState().getTracer(tx, null, sig, "Test/${className}/dude3", getTracerFlags(false, false, true));
    assertEquals(tracer, tx.getTransactionActivity().getLastTracer());
    assertEquals("Test/com.test.Dude/dude3", tracer.getMetricName());
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) UltraLightTracer(com.newrelic.agent.tracers.UltraLightTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) TracerFactory(com.newrelic.agent.tracers.TracerFactory) Test(org.junit.Test)

Aggregations

TracerFactory (com.newrelic.agent.tracers.TracerFactory)10 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)8 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)8 Tracer (com.newrelic.agent.tracers.Tracer)8 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)8 Test (org.junit.Test)8 Returns (org.mockito.internal.stubbing.answers.Returns)8 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)7 TransactionCounts (com.newrelic.agent.transaction.TransactionCounts)2 TracerFactoryException (com.newrelic.agent.TracerFactoryException)1 EntryInvocationHandler (com.newrelic.agent.tracers.EntryInvocationHandler)1 MethodTracerFactory (com.newrelic.api.agent.MethodTracerFactory)1