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 | Required. The URL of the request. |
string | Required. The HTTP method of the request. |
NRTimer | Required. A timer that captures the start and end of the request. |
double | Optional. A double that captures the start time of the request.
( |
double | Optional. A double that captures the end time of the request.
( |
NSDictionary | Required. A dictionary of the headers returned in the server response. |
NSUInteger | Required. The status code of the HTTP response. |
NSUInteger | Required. The number of bytes sent in the request body. |
NSUInteger | Required. The number of bytes received in the response body. |
NSData | Required. The response body data returned by the server. Used when recording a traced server error. |
NSDictionary | Nullable. Used for distributed tracing. |
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)