Search in sources :

Example 1 with TracedMethod

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

the class DB_Weave method command.

/*
     * Command calls db.$cmd.find({command}). Since that isn't actually a find operation we want to include its metrics
     * in this tracer. Hence, this tracer is a leaf.
     */
@Trace(leaf = true)
public CommandResult command(final DBObject command, final ReadPreference readPreference, final DBEncoder encoder) {
    String commandName = null;
    String collectionName = null;
    try {
        commandName = command.keySet().iterator().next();
        collectionName = String.valueOf(command.get(commandName));
    } catch (NoSuchElementException nse) {
        NewRelic.getAgent().getLogger().log(Level.FINER, "WARNING: Could not determine mongo command name.");
        commandName = MongoUtil.DEFAULT_OPERATION;
        collectionName = MongoUtil.DEFAULT_COLLECTION;
    }
    CommandResult result = Weaver.callOriginal();
    TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
    DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(collectionName).operation(commandName).instance(getMongo().getAddress().getHost(), getMongo().getAddress().getPort()).databaseName(getName()).build();
    tracedMethod.reportAsExternal(params);
    return result;
}
Also used : DatastoreParameters(com.newrelic.api.agent.DatastoreParameters) TracedMethod(com.newrelic.api.agent.TracedMethod) NoSuchElementException(java.util.NoSuchElementException) Trace(com.newrelic.api.agent.Trace)

Example 2 with TracedMethod

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

the class NettyDispatcher method channelRead.

@Trace(dispatcher = true)
public static void channelRead(ChannelHandlerContext_Instrumentation ctx, Object msg) {
    ctx.pipeline().token = AgentBridge.getAgent().getTransaction().getToken();
    TracedMethod tracer = AgentBridge.getAgent().getTransaction().getTracedMethod();
    if (tracer == null) {
        // it happens.
        AgentBridge.getAgent().getLogger().log(Level.FINEST, "Unable to dispatch netty tx. No tracer.");
    } else {
        tracer.setMetricName("NettyUpstreamDispatcher");
        AgentBridge.getAgent().getTransaction().setTransactionName(TransactionNamePriority.SERVLET_NAME, true, "NettyDispatcher", "NettyDispatcher");
    }
    Transaction tx = AgentBridge.getAgent().getTransaction(false);
    if (tx != null) {
        tx.setWebRequest(new RequestWrapper((HttpRequest) msg));
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Transaction(com.newrelic.agent.bridge.Transaction) RequestWrapper(com.agent.instrumentation.netty40.RequestWrapper) TracedMethod(com.newrelic.api.agent.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Example 3 with TracedMethod

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

the class CircuitBreakerApiTest method runTestExternalCatAPI.

@Trace(dispatcher = true)
private void runTestExternalCatAPI() {
    URL myURL = null;
    try {
        Thread.sleep(1000);
        myURL = new URL("http://localhost:8080");
        HttpUriRequest request = RequestBuilder.get().setUri(myURL.toURI()).build();
        ApiTestHelper.OutboundWrapper outboundWrapper = new ApiTestHelper.OutboundWrapper(request, HeaderType.HTTP);
        TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
        tracedMethod.addOutboundRequestHeaders(outboundWrapper);
        Assert.assertTrue(request.getHeaders("X-NewRelic-ID").length == 0);
        ApiTestHelper.DummyRequest incomingRequest = new ApiTestHelper.DummyRequest(HeaderType.HTTP);
        ApiTestHelper.DummyResponse response = new ApiTestHelper.DummyResponse(HeaderType.HTTP);
        NewRelic.getAgent().getTransaction().setWebRequest(incomingRequest);
        NewRelic.getAgent().getTransaction().setWebResponse(response);
        NewRelic.getAgent().getTransaction().addOutboundResponseHeaders();
        NewRelic.getAgent().getTransaction().markResponseSent();
        Assert.assertFalse(response.didSetHeader());
        Tracer rootTracer = Transaction.getTransaction().getRootTracer();
        Assert.assertNull(rootTracer);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail();
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) Tracer(com.newrelic.agent.tracers.Tracer) TracedMethod(com.newrelic.api.agent.TracedMethod) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) Trace(com.newrelic.api.agent.Trace)

Example 4 with TracedMethod

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

the class AmazonSNS_Instrumentation method publish.

@Trace
public PublishResult publish(PublishRequest publishRequest) {
    TracedMethod tracedMethod = NewRelic.getAgent().getTracedMethod();
    ExternalParameters params = SNSInstrumentationHelper.makeMessageProducerParameters(publishRequest);
    tracedMethod.reportAsExternal(params);
    return Weaver.callOriginal();
}
Also used : ExternalParameters(com.newrelic.api.agent.ExternalParameters) TracedMethod(com.newrelic.api.agent.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Example 5 with TracedMethod

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

the class NettyDispatcher method upstreamDispatcher.

@Trace(dispatcher = true)
public static void upstreamDispatcher(ChannelHandlerContext_Instrumentation ctx, Object msg) {
    try {
        ctx.getPipeline().token = AgentBridge.getAgent().getTransaction().getToken();
        TracedMethod tracer = AgentBridge.getAgent().getTransaction().getTracedMethod();
        if (tracer == null) {
            // it happens.
            AgentBridge.getAgent().getLogger().log(Level.FINEST, "Unable to dispatch netty tx. No tracer.");
        } else {
            tracer.setMetricName("NettyUpstreamDispatcher");
            AgentBridge.currentApiSource.set(WeavePackageType.INTERNAL);
            AgentBridge.getAgent().getTransaction().setTransactionName(TransactionNamePriority.SERVLET_NAME, true, "NettyDispatcher", "NettyDispatcher");
        }
        Transaction tx = AgentBridge.getAgent().getTransaction(false);
        if (tx != null) {
            tx.setWebRequest(new RequestWrapper((DefaultHttpRequest) msg));
        }
    } catch (Throwable t) {
        AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
    } finally {
        AgentBridge.currentApiSource.remove();
    }
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) RequestWrapper(com.agent.instrumentation.netty38.RequestWrapper) TracedMethod(com.newrelic.api.agent.TracedMethod) Trace(com.newrelic.api.agent.Trace)

Aggregations

Trace (com.newrelic.api.agent.Trace)5 TracedMethod (com.newrelic.api.agent.TracedMethod)5 Transaction (com.newrelic.agent.bridge.Transaction)2 RequestWrapper (com.agent.instrumentation.netty38.RequestWrapper)1 RequestWrapper (com.agent.instrumentation.netty40.RequestWrapper)1 Tracer (com.newrelic.agent.tracers.Tracer)1 DatastoreParameters (com.newrelic.api.agent.DatastoreParameters)1 ExternalParameters (com.newrelic.api.agent.ExternalParameters)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 NoSuchElementException (java.util.NoSuchElementException)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)1