use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.
the class NewRelicCommandListener method tryFinishEvent.
private void tryFinishEvent() {
try {
Segment tracerEvent = holder.get();
if (tracerEvent != null) {
tracerEvent.end();
holder.remove();
}
} catch (Throwable t) {
AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
}
}
use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.
the class NewRelicCommandListener method commandStarted.
@Override
public void commandStarted(CommandStartedEvent event) {
try {
Segment tracer = NewRelic.getAgent().getTransaction().startSegment(null);
if (tracer != null) {
holder.set(tracer);
String collectionName = getCollectionName(event);
String operationName = event.getCommandName().intern();
ServerAddress address = event.getConnectionDescription().getServerAddress();
DatastoreParameters params = DatastoreParameters.product(DatastoreVendor.MongoDB.name()).collection(collectionName).operation(operationName).instance(address.getHost(), address.getPort()).databaseName(event.getDatabaseName()).build();
tracer.reportAsExternal(params);
}
} catch (Throwable t) {
AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
}
}
use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.
the class AsyncHttpProvider method execute.
public <T> ListenableFuture<T> execute(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()) {
Segment segment = NewRelic.getAgent().getTransaction().startSegment("execute");
segment.addOutboundRequestHeaders(new OutboundWrapper(request));
handler.uri = uri;
handler.segment = segment;
}
} catch (URISyntaxException uriSyntaxException) {
// if Java can't parse the URI, ning won't be able to either
// let's just proceed without instrumentation
}
// proceed
return Weaver.callOriginal();
}
use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.
the class JavaPlayWSUtils method finish.
public static CompletionStage<? extends StandaloneWSResponse> finish(Segment segment, String procedure, StandaloneWSRequest request, CompletionStage<? extends StandaloneWSResponse> response) {
if (segment == null) {
return response;
}
final Segment localSegment = segment;
localSegment.setMetricName("External", "PlayWS", procedure);
try {
response = response.whenComplete(new BiConsumer<StandaloneWSResponse, Throwable>() {
@Override
public void accept(StandaloneWSResponse standaloneWSResponse, Throwable throwable) {
if (throwable != null) {
try {
localSegment.reportAsExternal(HttpParameters.library("PlayWS").uri(new URL(request.getUrl()).toURI()).procedure(procedure).noInboundHeaders().build());
localSegment.end();
} catch (Exception e) {
}
} else {
try {
localSegment.reportAsExternal(HttpParameters.library("PlayWS").uri(new URL(request.getUrl()).toURI()).procedure(procedure).inboundHeaders(new JavaInboundWrapper(standaloneWSResponse)).build());
localSegment.end();
} catch (Exception e) {
}
}
}
});
} catch (Throwable t) {
AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
try {
localSegment.end();
} catch (Throwable t1) {
AgentBridge.instrumentation.noticeInstrumentationError(t, Weaver.getImplementationTitle());
}
}
return response;
}
use of com.newrelic.api.agent.Segment in project newrelic-java-agent by newrelic.
the class StandaloneWSClient_Instrumentation method url.
public StandaloneWSRequest_Instrumentation url(String url) {
Segment segment = PlayWSUtils.start();
StandaloneWSRequest_Instrumentation request = Weaver.callOriginal();
Buffer<Tuple2<String, String>> headers = PlayWSUtils.createSeq();
segment.addOutboundRequestHeaders(new OutboundWrapper(headers));
request.segment = segment;
// This is here to ensure that we always add our outbound CAT headers
return request.addHttpHeaders(headers);
}
Aggregations