構文
NewRelic.noticeHttpTransaction(string $url, string $httpMethod, int $statusCode, long $startTime, long $endTime, long $bytesSent, long $bytesReceived [, string $responseBody])
ネットワークのリクエストを追跡する。
要件
すべてのAgentバージョンに対応しています。
説明
New Relic Android SDK API は、ネットワークリクエストやネットワーク障害を記録するためのいくつかのメソッドを提供しています。 noticeHttpTransaction
を使用すると、HTTP トランザクションを記録することができ、オプションでレスポンスボディも送信することができます。
ネットワークリクエストが失敗した場合、 noticeNetworkFailure()
で失敗の詳細を記録することができます。
New Relic Android SDK API の一般的な使用方法については、 使用ガイド をご参照ください。
パラメータ
パラメーター | 説明 |
---|---|
文字列 | 必須です。リクエストのURLです。 |
文字列 | 必要です。GETやPOSTなど、使用するHTTPメソッドです。 |
int | 必要です。 OK のような、HTTP レスポンスの statusCode です。 |
int | 必須。リクエストの開始時刻をエポックからのミリ秒で表したもの。 |
int | 必須。リクエストの終了時刻をエポックからのミリ秒で表したもの。 |
int | 必須です。リクエストで送信されたバイト数です。 |
int | 必須です。レスポンスで受信したバイト数。 |
文字列 | オプションです。HTTP レスポンスのレスポンス ボディです。レスポンス ボディは、HTTP トランザクションがエラーの場合、切り捨てられて HTTP エラー メトリックに含まれます。 |
例
HTTPトランザクションの記録
HTTP トランザクションのトラッキングの例です。
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; }}