Search in sources :

Example 1 with OutboundWrapper

use of com.nr.agent.instrumentation.okhttp34.OutboundWrapper in project newrelic-java-agent by newrelic.

the class HttpAsyncClient4_Instrumentation method execute.

/* Most common uses of the execute methods defined in the HttpAsyncClient interface should eventually call into this
     * particular execute signature, thus instrumenting only this one should result in fairly thorough instrumentation
     * coverage without double counting external calls. Possible exceptions include uses of execute in
     * CachingHttpAsyncClient and those defined in the HttpPipeliningClient interface.
     */
public <T> Future<T> execute(HttpAsyncRequestProducer requestProducer, HttpAsyncResponseConsumer_Instrumentation<T> responseConsumer, HttpContext context, FutureCallback<T> callback) {
    try {
        URI uri = new URI(requestProducer.getTarget().toURI());
        String scheme = uri.getScheme();
        final Transaction txn = AgentBridge.getAgent().getTransaction(false);
        // only instrument HTTP or HTTPS calls
        final String lowerCaseScheme = scheme.toLowerCase();
        if (("http".equals(lowerCaseScheme) || "https".equals(lowerCaseScheme)) && txn != null) {
            try {
                // Calls to generateRequest() don't appear to create a new HttpRequest object each time, but it does
                // seem like other people could implement their own version that does. Something to be aware of.
                final HttpRequest httpRequest = requestProducer.generateRequest();
                Segment segment = txn.startSegment("External");
                segment.addOutboundRequestHeaders(new OutboundWrapper(httpRequest));
                // forward uri and segment to HttpAsyncResponseConsumer_Instrumentation
                responseConsumer.segment = segment;
                responseConsumer.uri = uri;
            } catch (IOException | HttpException e) {
                AgentBridge.getAgent().getLogger().log(Level.FINEST, e, "Caught exception in HttpAsyncClient4 instrumentation: {0}");
            }
        }
    } catch (URISyntaxException uriSyntaxException) {
    // if Java can't parse the URI, HttpAsyncClient won't be able to either
    // let's just proceed without instrumentation
    }
    return Weaver.callOriginal();
}
Also used : HttpRequest(org.apache.http.HttpRequest) Transaction(com.newrelic.agent.bridge.Transaction) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Segment(com.newrelic.api.agent.Segment) OutboundWrapper(com.nr.agent.instrumentation.httpasyncclient4.OutboundWrapper)

Example 2 with OutboundWrapper

use of com.nr.agent.instrumentation.okhttp34.OutboundWrapper in project newrelic-java-agent by newrelic.

the class HttpMethodBase method execute.

@Trace(leaf = true)
public int execute(HttpState state, HttpConnection conn) throws IOException {
    String host = null;
    String uri = null;
    TracedMethod method = AgentBridge.getAgent().getTracedMethod();
    Transaction tx = AgentBridge.getAgent().getTransaction();
    if (!checkForIgnoredSocketCall(method)) {
        // URI calculation logic migrated from old pointcut to maintain parity
        URI methodURI = getURI();
        String scheme = methodURI.getScheme();
        if (scheme == null) {
            scheme = conn.getProtocol().getScheme();
            host = conn.getHost();
            String path = methodURI.getPath();
            if ("null".equals(path)) {
                path = null;
            }
            uri = URISupport.getURI(scheme, host, conn.getPort(), path);
        } else {
            host = methodURI.getHost();
            uri = URISupport.getURI(methodURI.getScheme(), host, conn.getPort(), methodURI.getPath());
        }
        // Set cross process headers for this outbound request
        method.addOutboundRequestHeaders(new OutboundWrapper(this));
    }
    int responseCode = Weaver.callOriginal();
    if (!checkForIgnoredSocketCall(method) && uri != null) {
        try {
            InboundWrapper inboundHeaders = new InboundWrapper(this);
            java.net.URI netURI = java.net.URI.create(uri);
            method.reportAsExternal(HttpParameters.library(LIBRARY).uri(netURI).procedure("execute").inboundHeaders(inboundHeaders).status(responseCode, this.getStatusText()).build());
        } catch (Throwable e) {
            AgentBridge.getAgent().getLogger().log(Level.FINER, e, "Unable to reportAsExternal for execute()");
        }
    }
    return responseCode;
}
Also used : Transaction(com.newrelic.agent.bridge.Transaction) InboundWrapper(com.nr.agent.instrumentation.httpclient31.InboundWrapper) TracedMethod(com.newrelic.agent.bridge.TracedMethod) OutboundWrapper(com.nr.agent.instrumentation.httpclient31.OutboundWrapper) Trace(com.newrelic.api.agent.Trace)

Example 3 with OutboundWrapper

use of com.nr.agent.instrumentation.okhttp34.OutboundWrapper in project newrelic-java-agent by newrelic.

the class RealCall_Instrumentation method doOutboundCAT.

/**
 * The original request is immutable, so internally the wrapper modifies a copy and saves it, which we need to
 * pull back out after adding the headers.
 */
private static Request doOutboundCAT(Request request) {
    OutboundWrapper out = new OutboundWrapper(request);
    NewRelic.getAgent().getTracedMethod().addOutboundRequestHeaders(out);
    return out.getRequestWithNRHeaders();
}
Also used : OutboundWrapper(com.nr.agent.instrumentation.okhttp34.OutboundWrapper)

Example 4 with OutboundWrapper

use of com.nr.agent.instrumentation.okhttp34.OutboundWrapper in project newrelic-java-agent by newrelic.

the class RealCall_Instrumentation method doOutboundCAT.

/**
 * The original request is immutable, so internally the wrapper modifies a copy and saves it, which we need to
 * pull back out after adding the headers.
 */
private static Request doOutboundCAT(Request request) {
    OutboundWrapper out = new OutboundWrapper(request);
    NewRelic.getAgent().getTracedMethod().addOutboundRequestHeaders(out);
    return out.getRequestWithNRHeaders();
}
Also used : OutboundWrapper(com.nr.agent.instrumentation.okhttp30.OutboundWrapper)

Aggregations

Transaction (com.newrelic.agent.bridge.Transaction)2 TracedMethod (com.newrelic.agent.bridge.TracedMethod)1 Segment (com.newrelic.api.agent.Segment)1 Trace (com.newrelic.api.agent.Trace)1 OutboundWrapper (com.nr.agent.instrumentation.httpasyncclient4.OutboundWrapper)1 InboundWrapper (com.nr.agent.instrumentation.httpclient31.InboundWrapper)1 OutboundWrapper (com.nr.agent.instrumentation.httpclient31.OutboundWrapper)1 OutboundWrapper (com.nr.agent.instrumentation.okhttp30.OutboundWrapper)1 OutboundWrapper (com.nr.agent.instrumentation.okhttp34.OutboundWrapper)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HttpException (org.apache.http.HttpException)1 HttpRequest (org.apache.http.HttpRequest)1