noticeHttpTransaction

NewRelic.noticeHttpTransaction(string $url, string $httpMethod, int $statusCode, long $startTime, long $endTime, long $bytesSent, long $bytesReceived [, string $responseBody])
Tracks networks requests.

Requirements

Compatible with all agent versions.

Description

The New Relic Android SDK API provides several methods to track network requests and network failures. You can use noticeHttpTransaction to record HTTP transactions, with an option to also send a response body.

If a network request fails, you can record details about the failure with noticeNetworkFailure().

For general info on using the New Relic Android SDK API, see the usage guide.

Parameters

Parameter Description

$url

string

Required. The URL of the request.

$httpMethod

string

Required. The HTTP method used, such as GET or POST.

$statusCode

int

Required. The statusCode of the HTTP response, such as 200 for OK.

$startTime

int

Required. The start time of the request in milliseconds since the epoch.

$endTime

int

Required. The end time of the request in milliseconds since the epoch.

$bytesSent

int

Required. The number of bytes sent in the request.

$bytesReceived

int

Required. The number of bytes received in the response.

$responseBody

string

Optional. The response body of the HTTP response. The response body will be truncated and included in an HTTP Error metric if the HTTP transaction is an error.

Example(s)

Record HTTP transaction

An example of tracking an HTTP transaction:

public class CustomHttpMetricsLogger implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        //collect request start time
        long t1 = System.nanoTime();
        //get the size of the request body
        long requestSize = null == request.body() ? 0 : request.body().contentLength();
        //proceed with the request
        Response response = chain.proceed(request);
        //capture the time when response returns
        long t2 = System.nanoTime();
        long responseSize = null == response.body() ? 0 : response.body().contentLength();
        //tell new relic to notice this request
        NewRelic.noticeHttpTransaction(request.urlString(), request.method(), response.code(), t1, t2, requestSize, responseSize);
        //return response for processing
        return response;
    }
}

For more help

Recommendations for learning more: