• English日本語한국어
  • Log inStart now

noticeNetworkRequest (iOS SDK API)

Syntax

+ (void)noticeNetworkRequestForURL:(NSURL*)url
httpMethod:(NSString*)httpMethod
withTimer:(NRTimer*)timer
responseHeaders:(NSDictionary*)headers
statusCode:(NSInteger)httpStatusCode
bytesSent:(NSUInteger)bytesSent
bytesReceived:(NSUInteger)bytesReceived
responseData:(NSData *)responseData
traceHeaders:(NSDictionary<NSString*,NSString*>* _Nullable)traceHeaders
andParams:(NSDictionary * _Nullable)params;

Manually record any transactional HTTP network request that completes.

Requirements

Compatible with all agent versions.

Description

New Relic will track the URL, response time, status code, and data sent and received.

If the response header's dictionary contains a X-NewRelic-AppData header, New Relic will track the association between the mobile app and the web server, and the New Relic UI will display the correlation and comparison of server vs. network vs. queue time.

If the HTTP status code indicates an error (400 and above), New Relic will also track this request as an error. The request header's dictionary and the response body data will be encoded as a server error in the New Relic UI.

Parameters

Parameter

Description

$url

URL

Required. The URL of the request.

$httpMethod

string

Required. The HTTP method of the request.

$timer

NRTimer

Required. A timer that captures the start and end of the request.

$startTime

double

Optional. A double that captures the start time of the request. (startTime and endTime can be used as an alternative to timer)

$endTime

double

Optional. A double that captures the end time of the request. (startTime and endTime can be used as an alternative to timer)

$responseHeaders

NSDictionary

Required. A dictionary of the headers returned in the server response.

$httpStatusCode

NSUInteger

Required. The status code of the HTTP response.

$bytesSent

NSUInteger

Required. The number of bytes sent in the request body.

$bytesReceived

NSUInteger

Required. The number of bytes received in the response body.

$responseData

NSData

Required. The response body data returned by the server. Used when recording a traced server error.

$traceHeaders

NSDictionary

Nullable. Used for distributed tracing.

$params

NSDictionary

Nullable. Unused.

Examples

Objective-C

Example:

[NewRelic noticeNetworkRequestForURL:[NSURL URLWithString:@"https://www.newrelic.com"] httpMethod:@"GET" withTimer:[[NRTimer alloc] init]
responseHeaders:@{} statusCode:200 bytesSent:1024 bytesReceived:52
responseData:[NSData data] traceHeaders:nil andParams:nil];

With start and end times

[NewRelic noticeNetworkRequestForURL:[NSURL URLWithString:@"https://www.newrelic.com"] httpMethod:@"GET" startTime:0.0 endTime:0.1
responseHeaders:@{} statusCode:200 bytesSent:1024 bytesReceived:52
responseData:[NSData data] traceHeaders:nil andParams:nil];

Swift

Example:

NewRelic.noticeNetworkRequest(for: URL(string: "https://www.newrelic.com"), httpMethod: "GET", with: NRTimer(), responseHeaders: [:],
statusCode: 200, bytesSent: 1000, bytesReceived: 1000, responseData: Data(), traceHeaders: nil, andParams: nil)

With start and end times

NewRelic.noticeNetworkRequest(for: URL(string: "https://www.newrelic.com"), httpMethod: "GET", startTime: 0.0, endTime: 0.1, responseHeaders: [:],
statusCode: 200, bytesSent: 1000, bytesReceived: 1000, responseData: Data(), traceHeaders: nil, andParams: nil)
Copyright © 2023 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.