Search in sources :

Example 21 with OtherRootTracer

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

the class CrossProcessTransactionStateImplTest method testRendersBothHeaders.

@Test
public void testRendersBothHeaders() {
    CrossProcessTransactionStateImpl crossProcessTransactionState = setupTestForDistributedTracing(true);
    OutboundHeadersMap headers = new OutboundHeadersMap(HeaderType.HTTP);
    crossProcessTransactionState.populateRequestMetadata(headers, new OtherRootTracer(ta, new ClassMethodSignature("my.class", "methodname", "something"), "object", null));
    assertTrue(headers.containsKey("newrelic"));
    assertTrue(headers.get("newrelic").length() > 0);
    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)

Example 22 with OtherRootTracer

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

the class AbstractPriorityTransactionNamingPolicyTest method startOtherTransaction.

private void startOtherTransaction() throws Exception {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("", "", "");
    MetricNameFormat format = new SimpleMetricNameFormat("");
    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 23 with OtherRootTracer

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

the class TransactionTimesTest method testTransactionTimes.

@Test
public void testTransactionTimes() throws InterruptedException {
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer root = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(root);
    DefaultTracer tracer1 = createDefaultTraer("hello1");
    tx.getTransactionActivity().tracerStarted(tracer1);
    DefaultTracer tracer2 = createDefaultTraer("hello2");
    tx.getTransactionActivity().tracerStarted(tracer2);
    Thread.sleep(10);
    tracer2.finish(0, null);
    tracer1.finish(0, null);
    root.finish(0, null);
    Assert.assertNotNull(stats);
    SimpleStatsEngine unscoped = stats.getUnscopedStats();
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransaction/all"));
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime/all"));
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransaction/myMetricName"));
    Assert.assertNotNull(unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime/myMetricName"));
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransaction/all").getCallCount());
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime").getCallCount());
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransaction/myMetricName").getCallCount());
    Assert.assertEquals(1, unscoped.getOrCreateResponseTimeStats("OtherTransactionTotalTime/myMetricName").getCallCount());
    SimpleStatsEngine scoped = stats.getScopedStats();
    Assert.assertNotNull(scoped.getOrCreateResponseTimeStats("Java/com.newrelic.agent.transaction.TransactionTimesTest/dude"));
    Assert.assertEquals(1, scoped.getOrCreateResponseTimeStats("Java/com.newrelic.agent.transaction.TransactionTimesTest/dude").getCallCount());
    Assert.assertEquals(root.getDuration(), tx.getTransactionTimer().getTotalSumTimeInNanos());
    Assert.assertEquals(root.getDuration(), tx.getTransactionTimer().getResponseTimeInNanos());
    Assert.assertEquals(1, tx.getFinishedChildren().size());
}
Also used : Transaction(com.newrelic.agent.Transaction) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleStatsEngine(com.newrelic.agent.stats.SimpleStatsEngine) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 24 with OtherRootTracer

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

the class TransactionTimesTest method createDispatcherTracer.

// Create a Tracer for tests that require one.
private OtherRootTracer createDispatcherTracer() {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    return new OtherRootTracer(tx, sig, this, new OtherTransSimpleMetricNameFormat("myMetricName"));
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 25 with OtherRootTracer

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

the class ApiTest method setRequestAndResponseFirstWins.

@Test
public void setRequestAndResponseFirstWins() throws Exception {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("otherRootTracer"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    Request firstRequest = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "firstWins", "", ""));
    Response firstResponse = new FirstResponse(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(firstRequest, firstResponse);
    Request secondRequest = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "thisIsABug", "", ""));
    Response secondResponse = new SecondResponse(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(secondRequest, secondResponse);
    tracer.finish(0, null);
    Assert.assertEquals(firstRequest.getRequestURI(), tx.getDispatcher().getUri());
    Assert.assertEquals(firstResponse.getStatus(), ((WebRequestDispatcher) tx.getDispatcher()).getStatus());
    String name = tx.getPriorityTransactionName().getName();
    Assert.assertNotEquals("WebTransaction/Uri/thisIsABug", name);
    Assert.assertEquals("WebTransaction/Uri/firstWins", name);
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TransactionDataList(com.newrelic.agent.TransactionDataList) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) 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