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