Search in sources :

Example 1 with MetricState

use of com.nr.agent.instrumentation.httpurlconnection.MetricState in project newrelic-java-agent by newrelic.

the class HttpURLConnection method getInputStream.

@Trace(leaf = true)
public synchronized InputStream getInputStream() throws IOException {
    MetricState metricState = lazyGetMetricState();
    TracedMethod method = AgentBridge.getAgent().getTracedMethod();
    metricState.getInputStreamPreamble(connected, this, method);
    InputStream inputStream;
    try {
        // This does a network request (if getResponseCode() wasn't called first)
        inputStream = Weaver.callOriginal();
    } catch (Exception e) {
        // This is the default legacy behavior of the AbstractExternalComponentTracer
        if (e instanceof UnknownHostException) {
            method.setMetricName("External", "UnknownHost", "HttpURLConnection");
        }
        throw e;
    }
    metricState.getInboundPostamble(this, method);
    return inputStream;
}
Also used : MetricState(com.nr.agent.instrumentation.httpurlconnection.MetricState) InputStream(java.io.InputStream) TracedMethod(com.newrelic.agent.bridge.TracedMethod) IOException(java.io.IOException) Trace(com.newrelic.api.agent.Trace)

Example 2 with MetricState

use of com.nr.agent.instrumentation.httpurlconnection.MetricState in project newrelic-java-agent by newrelic.

the class HttpURLConnection method getResponseCode.

@Trace(leaf = true)
public int getResponseCode() throws Exception {
    MetricState metricState = lazyGetMetricState();
    TracedMethod method = AgentBridge.getAgent().getTracedMethod();
    metricState.getResponseCodePreamble(this, method);
    int responseCodeValue;
    try {
        // This does a network request (if getInputStream() wasn't called first)
        responseCodeValue = Weaver.callOriginal();
    } catch (Exception e) {
        // This is the default legacy behavior of the AbstractExternalComponentTracer
        if (e instanceof UnknownHostException) {
            method.setMetricName("External", "UnknownHost", "HttpURLConnection");
        }
        throw e;
    }
    metricState.getInboundPostamble(this, method);
    return responseCodeValue;
}
Also used : MetricState(com.nr.agent.instrumentation.httpurlconnection.MetricState) TracedMethod(com.newrelic.agent.bridge.TracedMethod) IOException(java.io.IOException) Trace(com.newrelic.api.agent.Trace)

Aggregations

TracedMethod (com.newrelic.agent.bridge.TracedMethod)2 Trace (com.newrelic.api.agent.Trace)2 MetricState (com.nr.agent.instrumentation.httpurlconnection.MetricState)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)1