Search in sources :

Example 1 with OutboundWrapper

use of com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper 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();
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Segment(com.newrelic.api.agent.Segment) OutboundWrapper(com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper)

Example 2 with OutboundWrapper

use of com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper 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)2 OutboundWrapper (com.nr.agent.instrumentation.asynchttpclient.OutboundWrapper)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2