Search in sources :

Example 6 with TracedMethod

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

the class HttpMethodBase method releaseConnection.

@Trace(leaf = true)
public void releaseConnection() {
    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, "releaseConnection");
        } catch (Throwable e) {
            AgentBridge.getAgent().getLogger().log(Level.FINER, e, "Unable to record external metrics for releaseConnection()");
        }
    }
    Weaver.callOriginal();
}
Also used : TracedMethod(com.newrelic.agent.bridge.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Example 7 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(int maxlen) 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)

Example 8 with TracedMethod

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

the class ExternalMetricsTest method testNullHost.

@Test
public void testNullHost() throws Exception {
    TracedMethod tracedMethod = Mockito.mock(TracedMethod.class);
    Transaction transaction = Mockito.mock(Transaction.class);
    String nullHost = null;
    ExternalMetrics.makeExternalComponentTrace(transaction, tracedMethod, nullHost, "library", true, "http://uri", "operation");
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) TracedMethod(com.newrelic.agent.bridge.TracedMethod) Test(org.junit.Test)

Example 9 with TracedMethod

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

the class SnsClient_Instrumentation method publish.

@Trace
public PublishResponse publish(PublishRequest publishRequest) throws InvalidParameterException, InvalidParameterValueException, InternalErrorException, NotFoundException, EndpointDisabledException, PlatformApplicationDisabledException, AuthorizationErrorException, KmsDisabledException, KmsInvalidStateException, KmsNotFoundException, KmsOptInRequiredException, KmsThrottlingException, KmsAccessDeniedException, InvalidSecurityException, AwsServiceException, SdkClientException, SnsException {
    TracedMethod tracedMethod = AgentBridge.getAgent().getTracedMethod();
    ExternalParameters params = SnsClientInstrumentationHelper.makeMessageProducerParameters(publishRequest);
    tracedMethod.reportAsExternal(params);
    return Weaver.callOriginal();
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) TracedMethod(com.newrelic.agent.bridge.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Example 10 with TracedMethod

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

the class SegmentTest method testAsyncNamedTracedActivity.

/**
 * tracer(dispatcher) start
 * --tracedActivity start
 * --tracedActivity finish (On a different thread)
 * tracer finish
 * <p>
 * Transaction must have two txas due to the Segment being finished on another thread.
 * Segment tracer must correctly link to root tracer.
 */
@Test
public void testAsyncNamedTracedActivity() throws InterruptedException {
    final Tracer root = makeTransaction();
    Assert.assertNotNull(root);
    Assert.assertNotNull(root.getTransactionActivity().getTransaction());
    Thread.sleep(1);
    final TracedActivity activity = AgentBridge.getAgent().getTransaction().createAndStartTracedActivity();
    Assert.assertNotNull(activity);
    final AtomicReference<TracedMethod> tracedMethod = new AtomicReference<>();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tracedMethod.set(activity.getTracedMethod());
            activity.end();
        }
    };
    t.start();
    t.join();
    root.finish(Opcodes.ARETURN, null);
    // assert num children == 2
    assertTrue(root.getTransactionActivity().getTransaction().isFinished());
    assertTrue(tracedMethod.get() instanceof Tracer);
    assertEquals("Transaction activity context was not properly set", "activity", ((Tracer) tracedMethod.get()).getTransactionActivity().getAsyncContext());
    assertEquals("Segment name not set properly", "Custom/Unnamed Segment", ((Tracer) tracedMethod.get()).getMetricName());
    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 : TracedActivity(com.newrelic.agent.bridge.TracedActivity) 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)

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