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;
}
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);
}
});
}
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);
}
});
}
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);
}
});
}
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();
}
Aggregations