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);
}
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"));
}
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"));
}
}
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));
}
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));
}
Aggregations