Search in sources :

Example 6 with OtherRootTracer

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

the class TransactionTraceTest method excludeRootTraceFromTT.

/**
 * This test exercises an edge case in our public tracer api by setting excludeFromTransactionTrace = true on a root
 * tracer.
 *
 * The behavior is undefined, but in practice only the root tracer's segment is preserved in the TT. Scala
 * instrumentation is relying on this behavior by only showing the root scala future but not the consecutive calls.
 */
@Test
public void excludeRootTraceFromTT() throws Exception {
    setUp(true, true, false);
    Transaction tx = Transaction.getTransaction(true);
    TransactionActivity txa = TransactionActivity.get();
    // make sure the test env is sane
    Assert.assertNotNull(tx);
    Assert.assertNotNull(txa);
    Assert.assertEquals(tx, txa.getTransaction());
    final ClassMethodSignature sig = new ClassMethodSignature("Test", "dude", "()V");
    final MetricNameFormat metricNameFormat = new SimpleMetricNameFormat("Test.dude", "Test.dude");
    // @Trace( excludeFromTransactionTrace = true )
    final int excludeFromTTFlags = TracerFlags.GENERATE_SCOPED_METRIC;
    // @Trace
    final int defaultFlags = TracerFlags.GENERATE_SCOPED_METRIC | TracerFlags.TRANSACTION_TRACER_SEGMENT;
    DefaultTracer root = new OtherRootTracer(txa, sig, new Object(), metricNameFormat, excludeFromTTFlags, System.currentTimeMillis());
    txa.addTracer(root);
    Assert.assertEquals(txa, root.getTransactionActivity());
    Assert.assertEquals(tx, root.getTransaction());
    final int numChildren = 10;
    for (int i = 0; i < numChildren; ++i) {
        DefaultTracer child = new DefaultTracer(txa, sig, new Object(), metricNameFormat, excludeFromTTFlags, System.currentTimeMillis());
        txa.addTracer(child);
        child.finish(0, null);
        // child honor the flags and do not make a tt segment
        Assert.assertFalse(child.isTransactionSegment());
    }
    root.finish(0, null);
    Assert.assertEquals("Java/java.lang.Object/dude", TransactionSegment.getMetricName(root));
}
Also used : Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) JSONObject(org.json.simple.JSONObject) TransactionActivity(com.newrelic.agent.TransactionActivity) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MetricNameFormat(com.newrelic.agent.tracers.metricname.MetricNameFormat) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 7 with OtherRootTracer

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

the class TransactionEventsServiceTest method testSendOther.

@Test
public void testSendOther() throws Exception {
    setup(true, true, TEST_RESERVOIR_SIZE);
    TransactionActivityInitiator rootTracer = new OtherRootTracer(Transaction.getTransaction(), null, new Object(), null);
    TransactionData transactionData = new TransactionDataTestBuilder(APP_NAME, iAgentConfig, new MockDispatcherTracer()).setDispatcher(rootTracer.createDispatcher()).setFrontendMetricName("Frontend/metricname").build();
    TransactionStats transactionStats = new TransactionStats();
    transactionStats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.DISPATCHER).recordResponseTime(8, TimeUnit.MILLISECONDS);
    // populate the eventData map
    service.harvestEvents(APP_NAME);
    DistributedSamplingPriorityQueue<TransactionEvent> currentEventData = getEventData(APP_NAME);
    assertEquals(0, currentEventData.size());
    service.dispatcherTransactionFinished(transactionData, transactionStats);
    assertEquals(1, currentEventData.size());
}
Also used : TransactionActivityInitiator(com.newrelic.agent.tracers.TransactionActivityInitiator) TransactionStats(com.newrelic.agent.stats.TransactionStats) MockDispatcherTracer(com.newrelic.agent.MockDispatcherTracer) EventTestHelper.generateTransactionData(com.newrelic.agent.service.analytics.EventTestHelper.generateTransactionData) TransactionData(com.newrelic.agent.TransactionData) TransactionDataTestBuilder(com.newrelic.agent.TransactionDataTestBuilder) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 8 with OtherRootTracer

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

the class SlowQueryInfoTest method testDTAttributes.

@Test
public void testDTAttributes() {
    Map<String, Object> settings = new HashMap<>();
    Map<String, Object> dtMap = new HashMap<>();
    dtMap.put("enabled", true);
    settings.put("distributed_tracing", dtMap);
    Map<String, Object> spanConfig = new HashMap<>();
    spanConfig.put("collect_span_events", true);
    settings.put("span_events", spanConfig);
    setupServiceManager(settings);
    DistributedTraceServiceImpl dts = (DistributedTraceServiceImpl) ServiceFactory.getServiceManager().getDistributedTraceService();
    Map<String, Object> configMap = ImmutableMap.<String, Object>builder().put("distributed_tracing", ImmutableMap.builder().put("primary_application_id", "1app23").put("trusted_account_key", "1tak23").put("account_id", "1acct234").build()).build();
    dts.connected(null, AgentConfigFactory.createAgentConfig(configMap, null, null));
    Transaction.clearTransaction();
    Transaction transaction = Transaction.getTransaction();
    transaction.getTransactionActivity().tracerStarted(new OtherRootTracer(transaction, new ClassMethodSignature("class", "method", "desc"), null, new SimpleMetricNameFormat("test")));
    String inboundPayload = "{\n" + "  \"v\": [\n" + "    0,\n" + "    2\n" + "  ],\n" + "  \"d\": {\n" + "    \"ty\": \"App\",\n" + "    \"ac\": \"1acct789\",\n" + "    \"ap\": \"1app23\",\n" + "    \"id\": \"27856f70d3d314b7\",\n" + "    \"tr\": \"3221bf09aa0bcf0d\",\n" + "    \"tk\": \"1tak23\",\n" + "    \"pr\": 1.0002,\n" + "    \"sa\": true,\n" + "    \"tx\": \"123456\",\n" + "    \"ti\": 1482959525577\n" + "  }\n" + "}";
    transaction.acceptDistributedTracePayload(inboundPayload);
    TransactionData data = new TransactionData(transaction, 100);
    Tracer tracer = new DefaultTracer(transaction, new ClassMethodSignature("ClassName", "methodName", "methodDesc"), null, null, TracerFlags.DISPATCHER);
    String obfuscatedQuery = "select ? from ?";
    HashMap<String, Object> sqlMap = new HashMap<>();
    ServerProp serverProp = ServerProp.createPropObject(SqlTraceConfigImpl.DEFAULT_USE_LONGER_SQL_ID);
    sqlMap.put(SqlTraceConfigImpl.USE_LONGER_SQL_ID, serverProp);
    SqlTraceConfig sqlTraceConfig = SqlTraceConfigImpl.createSqlTraceConfig(sqlMap);
    SlowQueryInfo slowQueryInfo = new SlowQueryInfo(data, tracer, "select * from person", obfuscatedQuery, sqlTraceConfig);
    assertNotNull(transaction.getSpanProxy().getInboundDistributedTracePayload());
    Map<String, Object> parameters = slowQueryInfo.getParameters();
    assertEquals("App", parameters.get("parent.type"));
    assertEquals("1app23", parameters.get("parent.app"));
    assertEquals("1acct789", parameters.get("parent.account"));
    assertNotNull(parameters.get("parent.transportType"));
    assertNotNull(parameters.get("parent.transportDuration"));
    assertNotNull(parameters.get("guid"));
    assertEquals("3221bf09aa0bcf0d", parameters.get("traceId"));
    assertNotNull(parameters.get("priority"));
    assertEquals(true, parameters.get("sampled"));
}
Also used : HashMap(java.util.HashMap) DistributedTraceServiceImpl(com.newrelic.agent.tracing.DistributedTraceServiceImpl) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) SqlTraceConfig(com.newrelic.agent.config.SqlTraceConfig) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) TransactionData(com.newrelic.agent.TransactionData) ServerProp(com.newrelic.agent.config.ServerProp) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) Test(org.junit.Test)

Example 9 with OtherRootTracer

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

the class IntrospectorImplTest method createOtherTracer.

public static OtherRootTracer createOtherTracer(String methodName) {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature("MyClass", methodName, "()V");
    OtherRootTracer brrt = new OtherRootTracer(tx, sig, new Object(), new SimpleMetricNameFormat(methodName));
    return brrt;
}
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)

Example 10 with OtherRootTracer

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

the class ApiTest method testSetTransactionNameAfterGetBrowserInstrumentationFooter.

@Test
public void testSetTransactionNameAfterGetBrowserInstrumentationFooter() throws Exception {
    ApiTestHelper.mockOutServiceManager();
    Transaction tx = Transaction.getTransaction();
    tx.getTransactionActivity().tracerStarted(new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("dude")));
    NewRelic.setTransactionName("Test", "/foo1");
    NewRelic.getBrowserTimingHeader();
    // lock the name
    NewRelic.getBrowserTimingFooter();
    NewRelic.setTransactionName("Test", "/foo2");
    // still foo1 as the name has been locked and the second setting of the name is ignored (and a message is logged)
    Assert.assertEquals("OtherTransaction/Test/foo1", tx.getPriorityTransactionName().getName());
}
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)

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