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