Search in sources :

Example 1 with SimpleMetricNameFormat

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

the class DefaultTracer method setMetricName.

@Override
public void setMetricName(String... metricNameParts) {
    String metricName = Strings.join(MetricNames.SEGMENT_DELIMITER, metricNameParts);
    if (metricName != null) {
        setMetricNameFormat(new SimpleMetricNameFormat(metricName));
    }
    MetricNames.recordApiSupportabilityMetric(MetricNames.SUPPORTABILITY_API_SEGMENT_SET_METRIC_NAME);
}
Also used : SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 2 with SimpleMetricNameFormat

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

the class TransactionStateImplTest method createTracer.

private Tracer createTracer() throws Exception {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    return new DefaultTracer(tx, sig, this, new SimpleMetricNameFormat("test"));
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)

Example 3 with SimpleMetricNameFormat

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

the class TransactionTest method createDispatcherTracer.

// Create a Tracer for tests that require one.
private Tracer createDispatcherTracer(boolean createRequest) {
    Transaction tx = Transaction.getTransaction();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    if (createRequest) {
        MockHttpRequest httpRequest = new MockHttpRequest();
        MockHttpResponse httpResponse = new MockHttpResponse();
        return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
    } else {
        return new OtherRootTracer(tx, sig, this, new SimpleMetricNameFormat("thisismyname"));
    }
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer)

Example 4 with SimpleMetricNameFormat

use of com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat 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 5 with SimpleMetricNameFormat

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

the class TransactionTraceTest method testGetMetricName.

@Test
public void testGetMetricName() throws Exception {
    setUp(true, true, false);
    DefaultTracer tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("Test", "dude", "()V"), this, new SimpleMetricNameFormat("hello"));
    Assert.assertEquals("hello", TransactionSegment.getMetricName(tracer));
    tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("Test", "dude", "()V"), this, new SimpleMetricNameFormat("hello", "segmentName"));
    Assert.assertEquals("segmentName", TransactionSegment.getMetricName(tracer));
    tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("Test", "dude", "()V"), this, new SimpleMetricNameFormat("hello", "1234"));
    Assert.assertEquals("1234", TransactionSegment.getMetricName(tracer));
    // Writing this test based on the current code. No clue why we would ever want a segment named after the
    // tracer. This test proves that you can not get a null transaction segment metric name.
    tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("Test", "dude", "()V"), this, new SimpleMetricNameFormat("hello", ""));
    Assert.assertEquals("com.newrelic.agent.tracers.DefaultTracer*", TransactionSegment.getMetricName(tracer));
    tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("Test", "dude", "()V"), this, new SimpleMetricNameFormat("hello", null));
    Assert.assertEquals("com.newrelic.agent.tracers.DefaultTracer*", TransactionSegment.getMetricName(tracer));
    tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("Test", "dude", "()V"), this, new SimpleMetricNameFormat(null, null));
    Assert.assertEquals("com.newrelic.agent.tracers.DefaultTracer*", TransactionSegment.getMetricName(tracer));
    tracer = new DefaultTracer(Transaction.getTransaction(), new ClassMethodSignature("Test", "dude", "()V"), this, new SimpleMetricNameFormat("hello", "           "));
    Assert.assertEquals("com.newrelic.agent.tracers.DefaultTracer*", TransactionSegment.getMetricName(tracer));
}
Also used : DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) OtherTransSimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.OtherTransSimpleMetricNameFormat) Test(org.junit.Test)

Aggregations

SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)70 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)46 Transaction (com.newrelic.agent.Transaction)43 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)34 Test (org.junit.Test)32 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)11 Response (com.newrelic.api.agent.Response)10 Tracer (com.newrelic.agent.tracers.Tracer)9 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)9 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 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)7 TransactionDataList (com.newrelic.agent.TransactionDataList)6