• /
  • Log in
  • Free account

noticeHttpTransaction (Android SDK API)


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

Tracks networks requests.


Compatible with all agent versions.


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.






Required. The URL of the request.



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



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



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



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



Required. The number of bytes sent in the request.



Required. The number of bytes received in the response.



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.


Record HTTP transaction

An example of tracking an HTTP transaction:

public class CustomHttpMetricsLogger implements Interceptor {
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

If you need more help, check out these support and learning resources:

Create issueEdit page
Copyright © 2021 New Relic Inc.