Search in sources :

Example 1 with TracedMethod

use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.

the class SegmentTest method testSyncNamedTracedActivity.

/**
 * tracer(dispatcher) start
 * --tracedActivity start
 * tracer finish
 * --tracedActivity finish
 * <p>
 * Transaction must have two txas due to the tracedActivity being finished after its parent tracer is finished.
 * Segment tracer must correctly link to root tracer.
 */
@Test
public void testSyncNamedTracedActivity() throws InterruptedException {
    Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    Thread.sleep(1);
    final Segment segment = root.getTransactionActivity().getTransaction().startSegment(MetricNames.CUSTOM, "Custom Segment");
    Assert.assertNotNull(segment);
    root.finish(Opcodes.ARETURN, null);
    Thread.sleep(1);
    final AtomicReference<TracedMethod> tracedMethod = new AtomicReference<>();
    tracedMethod.set(segment.getTracedMethod());
    segment.end();
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    assertTrue(tracedMethod.get() instanceof Tracer);
    assertEquals("Segment name was not properly set", "activity", ((Tracer) tracedMethod.get()).getTransactionActivity().getAsyncContext());
    assertEquals(2, root.getTransactionActivity().getTransaction().getCountOfRunningAndFinishedTransactionActivities());
    assertEquals(2, getNumTracers(root.getTransactionActivity().getTransaction()));
    Assert.assertSame("Segment must be child of root tracer", root, tracedMethod.get().getParentTracedMethod());
}
Also used : ExitTracer(com.newrelic.agent.bridge.ExitTracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) Tracer(com.newrelic.agent.tracers.Tracer) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) TracedMethod(com.newrelic.agent.bridge.TracedMethod) Test(org.junit.Test)

Example 2 with TracedMethod

use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.

the class FlyweightTraceMethodVisitorTest method verifyTracedMethodStitching.

@Test
public void verifyTracedMethodStitching() {
    // these methods are overridden in the bridge with a different signature. ignore them
    Set<Method> excludes = ImmutableSet.of(new Method("getParentTracedMethod", "()Lcom/newrelic/api/agent/TracedMethod;"));
    TraceDetails trace = TraceDetailsBuilder.newBuilder().build();
    FlyweightTraceMethodVisitor mv = new FlyweightTraceMethodVisitor("", null, 0, "go", "()V", trace, null);
    Map<Method, ?> map = mv.tracedMethodMethodHandlers;
    java.lang.reflect.Method[] methods = TracedMethod.class.getMethods();
    for (java.lang.reflect.Method m : methods) {
        Method method = Method.getMethod(m);
        if (!map.containsKey(method) && !excludes.contains(method)) {
            Assert.fail("There is no method handler for TracedMethod." + method);
        }
    }
}
Also used : Method(org.objectweb.asm.commons.Method) TracedMethod(com.newrelic.agent.bridge.TracedMethod) Test(org.junit.Test)

Example 3 with TracedMethod

use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.

the class MetricState method nonNetworkPreamble.

public void nonNetworkPreamble(boolean isConnected, HttpURLConnection connection, String operation) {
    TracedMethod method = AgentBridge.getAgent().getTracedMethod();
    Transaction tx = AgentBridge.getAgent().getTransaction(false);
    if (!isConnected && method.isMetricProducer() && tx != null) {
        // This method doesn't have any network I/O so we are explicitly not recording external rollup metrics
        makeMetric(connection, method, operation);
        tx.getCrossProcessState().processOutboundRequestHeaders(new OutboundWrapper(connection), method);
    }
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) TracedMethod(com.newrelic.agent.bridge.TracedMethod)

Example 4 with TracedMethod

use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.

the class HttpURLConnection method getInputStream.

@Trace(leaf = true)
public synchronized InputStream getInputStream() throws IOException {
    MetricState metricState = lazyGetMetricState();
    TracedMethod method = AgentBridge.getAgent().getTracedMethod();
    metricState.getInputStreamPreamble(connected, this, method);
    InputStream inputStream;
    try {
        // This does a network request (if getResponseCode() wasn't called first)
        inputStream = Weaver.callOriginal();
    } catch (Exception e) {
        // This is the default legacy behavior of the AbstractExternalComponentTracer
        if (e instanceof UnknownHostException) {
            method.setMetricName("External", "UnknownHost", "HttpURLConnection");
        }
        throw e;
    }
    metricState.getInboundPostamble(this, method);
    return inputStream;
}
Also used : MetricState(com.nr.agent.instrumentation.httpurlconnection.MetricState) InputStream(java.io.InputStream) TracedMethod(com.newrelic.agent.bridge.TracedMethod) IOException(java.io.IOException) Trace(com.newrelic.api.agent.Trace)

Example 5 with TracedMethod

use of com.newrelic.agent.bridge.TracedMethod in project newrelic-java-agent by newrelic.

the class HttpMethodBase method getResponseBody.

@Trace(leaf = true)
public byte[] getResponseBody() throws IOException {
    TracedMethod method = AgentBridge.getAgent().getTracedMethod();
    if (!checkForIgnoredSocketCall(method)) {
        try {
            String host = getHostname();
            URI methodURI = getURI();
            String uri = URISupport.getURI(methodURI.getScheme(), methodURI.getHost(), methodURI.getPort(), methodURI.getPath());
            // This method doesn't have any network I/O so we are explicitly not recording external rollup metrics
            ExternalMetrics.makeExternalComponentMetric(method, host, LIBRARY, false, uri, "getResponseBody");
        } catch (Throwable e) {
            AgentBridge.getAgent().getLogger().log(Level.FINER, e, "Unable to record external metrics for getResponseBody()");
        }
    }
    return Weaver.callOriginal();
}
Also used : TracedMethod(com.newrelic.agent.bridge.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Aggregations

TracedMethod (com.newrelic.agent.bridge.TracedMethod)16 Trace (com.newrelic.api.agent.Trace)8 Transaction (com.newrelic.agent.bridge.Transaction)6 Test (org.junit.Test)4 Method (org.objectweb.asm.commons.Method)4 ExitTracer (com.newrelic.agent.bridge.ExitTracer)2 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)2 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)2 Tracer (com.newrelic.agent.tracers.Tracer)2 MetricState (com.nr.agent.instrumentation.httpurlconnection.MetricState)2 IOException (java.io.IOException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Label (org.objectweb.asm.Label)2 Type (org.objectweb.asm.Type)2 AdviceAdapter (org.objectweb.asm.commons.AdviceAdapter)2 Instrumentation (com.newrelic.agent.bridge.Instrumentation)1 PublicApi (com.newrelic.agent.bridge.PublicApi)1 TracedActivity (com.newrelic.agent.bridge.TracedActivity)1 PointCut (com.newrelic.agent.instrumentation.PointCut)1 Variables (com.newrelic.agent.util.asm.Variables)1