Search in sources :

Example 66 with Segment

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

the class SnsAsyncClient_Instrumentation method publish.

@SuppressWarnings("Convert2Lambda")
@Trace
public CompletableFuture<PublishResponse> publish(PublishRequest publishRequest) {
    final Segment segment = startSegmentAndReportAsExternal(publishRequest);
    AgentBridge.getAgent().getTracedMethod().setTrackChildThreads(false);
    CompletableFuture<PublishResponse> result = Weaver.callOriginal();
    if (result == null) {
        // this should never happen, but protecting against bad implementations
        segment.end();
    } else {
        result.whenComplete(new BiConsumer<PublishResponse, Throwable>() {

            @Override
            public void accept(PublishResponse publishResponse, Throwable throwable) {
                try {
                    segment.end();
                } catch (Throwable t) {
                    AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
                }
            }
        });
    }
    return result;
}
Also used : PublishResponse(software.amazon.awssdk.services.sns.model.PublishResponse) Segment(com.newrelic.api.agent.Segment) Trace(com.newrelic.api.agent.Trace)

Example 67 with Segment

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

the class SqsAsyncClient_Instrumentation method sendMessage.

public CompletableFuture<SendMessageResponse> sendMessage(SendMessageRequest sendMessageRequest) {
    Segment segment = NewRelic.getAgent().getTransaction().startSegment(Util.LIBRARY, "sendMessage");
    segment.reportAsExternal(Util.generateExternalProduceMetrics(sendMessageRequest.queueUrl()));
    AgentBridge.getAgent().getTracedMethod().setTrackChildThreads(false);
    CompletableFuture<SendMessageResponse> result = Weaver.callOriginal();
    if (result == null) {
        return null;
    }
    return result.whenComplete(new BiConsumer<SendMessageResponse, Throwable>() {

        @Override
        public void accept(SendMessageResponse sendMessageResponse, Throwable throwable) {
            Util.finishSegment(segment);
        }
    });
}
Also used : SendMessageResponse(software.amazon.awssdk.services.sqs.model.SendMessageResponse) Segment(com.newrelic.api.agent.Segment)

Example 68 with Segment

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

the class SqsAsyncClient_Instrumentation method sendMessageBatch.

public CompletableFuture<SendMessageBatchResponse> sendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest) {
    Segment segment = NewRelic.getAgent().getTransaction().startSegment(Util.LIBRARY, "sendMessageBatch");
    segment.reportAsExternal(Util.generateExternalProduceMetrics(sendMessageBatchRequest.queueUrl()));
    AgentBridge.getAgent().getTracedMethod().setTrackChildThreads(false);
    CompletableFuture<SendMessageBatchResponse> result = Weaver.callOriginal();
    if (result == null) {
        return null;
    }
    return result.whenComplete(new BiConsumer<SendMessageBatchResponse, Throwable>() {

        @Override
        public void accept(SendMessageBatchResponse sendMessageBatchResponse, Throwable throwable) {
            Util.finishSegment(segment);
        }
    });
}
Also used : SendMessageBatchResponse(software.amazon.awssdk.services.sqs.model.SendMessageBatchResponse) Segment(com.newrelic.api.agent.Segment)

Example 69 with Segment

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

the class SqsAsyncClient_Instrumentation method receiveMessage.

public CompletableFuture<ReceiveMessageResponse> receiveMessage(ReceiveMessageRequest receiveMessageRequest) {
    Segment segment = NewRelic.getAgent().getTransaction().startSegment(Util.LIBRARY, "receiveMessage");
    segment.reportAsExternal(Util.generateExternalConsumeMetrics(receiveMessageRequest.queueUrl()));
    AgentBridge.getAgent().getTracedMethod().setTrackChildThreads(false);
    CompletableFuture<ReceiveMessageResponse> result = Weaver.callOriginal();
    if (result == null) {
        return null;
    }
    return result.whenComplete(new BiConsumer<ReceiveMessageResponse, Throwable>() {

        @Override
        public void accept(ReceiveMessageResponse receiveMessageResponse, Throwable throwable) {
            Util.finishSegment(segment);
        }
    });
}
Also used : ReceiveMessageResponse(software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse) Segment(com.newrelic.api.agent.Segment)

Example 70 with Segment

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

the class AsyncHttpClient method executeRequest.

public <T> ListenableFuture<T> executeRequest(Request request, NRAsyncHandler<T> handler) {
    URI uri = null;
    try {
        uri = new URI(request.getUrl());
        String scheme = uri.getScheme();
        // only instrument HTTP or HTTPS calls
        if ((scheme == null || scheme.equals("http") || scheme.equals("https")) && null != AgentBridge.getAgent().getTransaction(false) && AgentBridge.getAgent().getTransaction().isStarted()) {
            // start the activity
            Segment segment = AgentBridge.getAgent().getTransaction().startSegment("External");
            if (null != segment) {
                segment.addOutboundRequestHeaders(new OutboundWrapper(request));
                handler.uri = uri;
                handler.segment = segment;
            }
        }
    } catch (URISyntaxException uriSyntaxException) {
    // if Java can't parse the URI, asynchttpclient won't be able to either
    // let's just proceed without instrumentation
    }
    // proceed
    return Weaver.callOriginal();
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Segment(com.newrelic.api.agent.Segment) OutboundWrapper(com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper)

Aggregations

Segment (com.newrelic.api.agent.Segment)138 Trace (com.newrelic.api.agent.Trace)13 URI (java.net.URI)6 NoOpSegment (com.newrelic.agent.bridge.NoOpSegment)5 URISyntaxException (java.net.URISyntaxException)4 HttpResponse (akka.http.scaladsl.model.HttpResponse)3 Transaction (com.newrelic.agent.bridge.Transaction)3 DatastoreParameters (com.newrelic.api.agent.DatastoreParameters)3 ExternalParameters (com.newrelic.api.agent.ExternalParameters)3 InetSocketAddress (java.net.InetSocketAddress)3 Test (org.junit.Test)3 Transaction (com.newrelic.agent.Transaction)2 MessageProduceParameters (com.newrelic.api.agent.MessageProduceParameters)2 Transaction (com.newrelic.api.agent.Transaction)2 OutboundWrapper (com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper)2 HelloReply (io.grpc.examples.helloworld.HelloReply)2 HelloRequest (io.grpc.examples.helloworld.HelloRequest)2 IOException (java.io.IOException)2 SocketAddress (java.net.SocketAddress)2 MemcachedNode (net.spy.memcached.MemcachedNode)2