Search in sources :

Example 16 with OtherRootTracer

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

the class ApiTest method testIgnoreTransaction.

@Test
public void testIgnoreTransaction() {
    Transaction tx = Transaction.getTransaction();
    tx.getTransactionActivity().tracerStarted(new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("dude")));
    NewRelic.ignoreTransaction();
    Assert.assertTrue("Transaction should be ignored", tx.isIgnore());
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 17 with OtherRootTracer

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

the class CustomTracerFactoryTest method testTracerWithParent.

@Test
public void testTracerWithParent() {
    Transaction transaction = Transaction.getTransaction();
    transaction.getTransactionActivity().tracerStarted(new OtherRootTracer(transaction, signature, this, new SimpleMetricNameFormat("test")));
    TracingMethodTracerFactory mtf = new TracingMethodTracerFactory();
    CustomTracerFactory factory = new CustomTracerFactory(mtf);
    Tracer tracer = factory.getTracer(transaction, signature, this, new Object[0]);
    Assert.assertFalse(tracer instanceof TransactionActivityInitiator);
    Assert.assertNotNull(mtf.tracer);
    Exception ex = new Exception();
    tracer.finish(ex);
    Assert.assertEquals(ex, mtf.tracer.exception);
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) Transaction(com.newrelic.agent.Transaction) Tracer(com.newrelic.agent.tracers.Tracer) MethodTracer(com.newrelic.api.agent.MethodTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 18 with OtherRootTracer

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

the class TransactionNamingTest method startOtherTransaction.

private void startOtherTransaction(String uri) throws Exception {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("", "", "");
    MetricNameFormat format = new SimpleMetricNameFormat(uri);
    Tracer tracer = new OtherRootTracer(tx, sig, this, format);
    tx.getTransactionActivity().tracerStarted(tracer);
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 19 with OtherRootTracer

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

the class CustomTracerFactory method doGetTracer.

@Override
public Tracer doGetTracer(Transaction transaction, ClassMethodSignature sig, Object object, Object[] args) {
    Tracer parent = transaction.getTransactionActivity().getLastTracer();
    final MethodTracer methodTracer = tracerFactory.methodInvoked(sig.getMethodName(), object, args);
    // no custom method tracer, just hook up a normal tracer
    if (methodTracer == null) {
        return parent == null ? new OtherRootTracer(transaction, sig, object, new ClassMethodMetricNameFormat(sig, object)) : new DefaultTracer(transaction, sig, object);
    } else // otherwise we have to let the method tracer know when the method exits
    {
        // DefaultTracer. This is the safest way to implement this for now.
        if (parent == null) {
            return new OtherRootTracer(transaction, sig, object, new ClassMethodMetricNameFormat(sig, object)) {

                @Override
                protected void doFinish(Throwable throwable) {
                    super.doFinish(throwable);
                    methodTracer.methodFinishedWithException(throwable);
                }

                @Override
                protected void doFinish(int opcode, Object returnValue) {
                    super.doFinish(opcode, returnValue);
                    methodTracer.methodFinished(returnValue);
                }
            };
        } else {
            return new DefaultTracer(transaction, sig, object) {

                @Override
                protected void doFinish(Throwable throwable) {
                    super.doFinish(throwable);
                    methodTracer.methodFinishedWithException(throwable);
                }

                @Override
                protected void doFinish(int opcode, Object returnValue) {
                    super.doFinish(opcode, returnValue);
                    methodTracer.methodFinished(returnValue);
                }
            };
        }
    }
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) MethodTracer(com.newrelic.api.agent.MethodTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) MethodTracer(com.newrelic.api.agent.MethodTracer) Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 20 with OtherRootTracer

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

the class CrossProcessTransactionStateImplTest method testRendersJustW3CWhenNewRelicHeaderExcluded.

@Test
public void testRendersJustW3CWhenNewRelicHeaderExcluded() {
    CrossProcessTransactionStateImpl crossProcessTransactionState = setupTestForDistributedTracing(false);
    OutboundHeadersMap headers = new OutboundHeadersMap(HeaderType.HTTP);
    crossProcessTransactionState.populateRequestMetadata(headers, new OtherRootTracer(ta, new ClassMethodSignature("my.class", "methodname", "something"), "object", null));
    assertFalse(headers.containsKey("newrelic"));
    assertTrue(headers.containsKey("traceparent"));
    assertTrue(headers.get("traceparent").length() > 0);
    assertTrue(headers.containsKey("tracestate"));
    assertTrue(headers.get("tracestate").length() > 0);
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

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