Search in sources :

Example 41 with ClassMethodSignature

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

the class TransactionNamingTest method startWebTransaction.

private void startWebTransaction(String uri) throws Exception {
    Transaction tx = Transaction.getTransaction();
    MockHttpRequest httpRequest = new MockHttpRequest();
    httpRequest.setRequestURI(uri);
    MockHttpResponse httpResponse = new MockHttpResponse();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    Tracer tracer = new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
    tx.getTransactionActivity().tracerStarted(tracer);
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) 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) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Example 42 with ClassMethodSignature

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

the class JsonTracer method generateDefaultTracer.

private DefaultTracer generateDefaultTracer(long txaStartTime) {
    ClassMethodSignature sig = new ClassMethodSignature("clazz", tracerName, "()");
    Object reference = new Object();
    DefaultTracer tracer = new DefaultTracer(Transaction.getTransaction().getTransactionActivity(), sig, reference, new ClassMethodMetricNameFormat(sig, reference), txaStartTime + startTimeNs);
    Transaction.getTransaction().getTransactionActivity().tracerStarted(tracer);
    return tracer;
}
Also used : ClassMethodMetricNameFormat(com.newrelic.agent.tracers.metricname.ClassMethodMetricNameFormat) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) JSONObject(org.json.simple.JSONObject)

Example 43 with ClassMethodSignature

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

the class JSFTest method testPhase.

@Test
public void testPhase() {
    final List<Tracer> tracers = new ArrayList<>();
    final MockFacesContext mockFacesContext = new MockFacesContext();
    final Phase phase = new Phase() {

        @Override
        public void execute(FacesContext arg0) throws FacesException {
            Tracer lastTracer = Transaction.getTransaction().getTransactionActivity().getLastTracer();
            tracers.add(lastTracer);
        }

        @Override
        protected void handleAfterPhase(FacesContext arg0, ListIterator<PhaseListener> arg1, PhaseEvent arg2) {
        }

        @Override
        protected void handleBeforePhase(FacesContext arg0, ListIterator<PhaseListener> arg1, PhaseEvent arg2) {
        }

        @Override
        protected void queueException(FacesContext ctx, Throwable t, String booleanKey) {
            super.queueException(ctx, t, booleanKey);
        }

        @Override
        protected void queueException(FacesContext ctx, Throwable t) {
            super.queueException(ctx, t);
        }

        @Override
        public PhaseId getId() {
            return PhaseId.ANY_PHASE;
        }
    };
    new Runnable() {

        @Override
        @Trace(dispatcher = true)
        public void run() {
            phase.doPhase(mockFacesContext, new MockLifecycle(), new ArrayList<PhaseListener>().listIterator());
        }
    }.run();
    Assert.assertEquals(1, tracers.size());
    Tracer tracer = tracers.get(0);
    ClassMethodSignature sig = new ClassMethodSignature(phase.getClass().getName(), "doPhase", "(Ljavax/faces/context/FacesContext;Ljavax/faces/lifecycle/Lifecycle;Ljava/util/ListIterator;)V");
    Assert.assertEquals(ClassMethodMetricNameFormat.getMetricName(sig, phase, MetricNames.CUSTOM), tracer.getMetricName());
}
Also used : MockFacesContext(com.sun.faces.mock.MockFacesContext) MockLifecycle(com.sun.faces.mock.MockLifecycle) MockFacesContext(com.sun.faces.mock.MockFacesContext) FacesContext(javax.faces.context.FacesContext) Phase(com.sun.faces.lifecycle.Phase) PhaseEvent(javax.faces.event.PhaseEvent) Tracer(com.newrelic.agent.tracers.Tracer) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) Trace(com.newrelic.api.agent.Trace) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) PhaseListener(javax.faces.event.PhaseListener) Test(org.junit.Test)

Example 44 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature 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);
}
Also used : ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) Test(org.junit.Test)

Example 45 with ClassMethodSignature

use of com.newrelic.agent.tracers.ClassMethodSignature 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)

Aggregations

ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)112 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)69 Transaction (com.newrelic.agent.Transaction)60 Test (org.junit.Test)55 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)46 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)44 Tracer (com.newrelic.agent.tracers.Tracer)41 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)26 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)23 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)20 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)17 HashMap (java.util.HashMap)17 TransactionData (com.newrelic.agent.TransactionData)16 JSONObject (org.json.simple.JSONObject)15 MetricNameFormat (com.newrelic.agent.tracers.metricname.MetricNameFormat)13 UltraLightTracer (com.newrelic.agent.tracers.UltraLightTracer)12 JSONArray (org.json.simple.JSONArray)11 MethodExitTracer (com.newrelic.agent.tracers.MethodExitTracer)10 Response (com.newrelic.api.agent.Response)10 TransactionDataTestBuilder (com.newrelic.agent.TransactionDataTestBuilder)9