Search in sources :

Example 1 with StandaloneWSResponse

use of play.libs.ws.StandaloneWSResponse 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;
}
Also used : StandaloneWSResponse(play.libs.ws.StandaloneWSResponse) Segment(com.newrelic.api.agent.Segment) BiConsumer(java.util.function.BiConsumer) URL(java.net.URL)

Aggregations

Segment (com.newrelic.api.agent.Segment)1 URL (java.net.URL)1 BiConsumer (java.util.function.BiConsumer)1 StandaloneWSResponse (play.libs.ws.StandaloneWSResponse)1