• /
  • EnglishEspañol日本語한국어Português
  • EntrarComeçar agora

Track failing HTTP transactions

Syntax

Java

NewRelic.noticeNetworkFailure(string $url, string $httpMethod, long $startTime, long $endTime, exception $exception OR enum $networkFailure)

Kotlin

NewRelic.noticeNetworkFailure(
url: String?,
httpMethod: String?,
startTime: Long,
endTime: Long,
failure: NetworkFailure?,
)

Description

The New Relic Android SDK API provides several methods to track network requests. If a network request fails, you can record details about the failure with noticeNetworkFailure. In most cases, place this call inside exception handlers, such as catch blocks.

Parameters

Parameter

Type

Description

$url

string

Required. The URL of the request.

$httpMethod

string

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

$startTime

long

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

$endTime

long

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

$exception

string

Either this or $failure parameter is required. This is the exception that occurred. New Relic can automatically translate many common exceptions into network failure types.

$failure

enum

Either this or $exception parameter is required. The type of network failure that occurred. If an exception cannot be resolved to a network failure automatically, this method can be used to categorize the failure accurately. The values are defined by the NetworkFailure enum. Valid values include Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, and SecureConnectionFailed.

Examples

Here’s an example of an error listener that uses an error as part of the noticed network failure to New Relic:

Java

new Response.ErrorListener() {
@Override
public void onErrorResponse(Error error) {
NewRelic.noticeNetworkFailure(badUrl, "GET", System.nanoTime(),
System.nanoTime(), NetworkFailure.exceptionToNetworkFailure(error));
}
}

Kotlin

NewRelic.noticeNetworkFailure(
badUrl,
"GET",
System.nanoTime(),
System.nanoTime(),
NetworkFailure.exceptionToNetworkFailure(error)
)

Syntax

Objective-c

+ (void)noticeNetworkFailureForURL:(NSURL*)url
httpMethod:(NSString*)httpMethod
withTimer:(NRTimer*)timer
andFailureCode:(NSInteger)iOSFailureCode;

Swift

func noticeNetworkFailure(for: URL, httpMethod: String, with: NRTimer, andFailureCode: Int)

Description

Failed requests are requests that fail to receive a complete response from the server caused by things like TCP timeouts, SSL failures, connection closures, and more.

Parameters

Parameter

Type

Description

$url

NSURL

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.

$iOSFailureCode

NSInteger

Required. The failure codes you pass into this method should correlate to Apple's documented NSURLConnection failure codes.

Examples

Objective-C

[NewRelic noticeNetworkFailureForURL:[NSURL URLWithString:@"https://www.newrelic.com"]
httpMethod:@"GET"
withTimer:[[NRTimer alloc] init]
andFailureCode:NSURLErrorTimedOut];

Swift

NewRelic.noticeNetworkFailure(for: URL(string: "https://www.newrelic.com"), httpMethod: "GET",
with: NRTimer(), andFailureCode: NSURLErrorTimedOut)

Syntax

noticeNetworkFailure(url: string, httpMethod: string, startTime: number, endTime: number, failure: string): void;

Description

Records network failures. If a network request fails, use this method to record details about the failures.

Parameters

Parameter

Type

Description

url

string

Required. The URL of the request.

httpMethod

string

Required. The HTTP method of the request.

startTime

number

Optional. The start time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

endTime

number

Optional. The end time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

failure

string

Optional. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, SecureConnectionFailed.

Example

NewRelic.noticeNetworkFailure('https://fakewebsite.com', 'GET', Date.now(), Date.now(), 'BadURL');

Syntax

void NoticeNetworkFailure(string url, string httpMethod, long startTime, long endTime, NetworkFailure failure);

Description

Records network failures. If a network request fails, use this method to record details about the failure.

Parameters

Parameter

Type

Description

url

string

Required. The URL of the request.

httpMethod

string

Required. The HTTP method of the request.

startTime

number

Optional. The start time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

endTime

number

Optional. The end time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

failure

string

Optional. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, SecureConnectionFailed.

Example

CrossNewRelic.Current.NoticeNetworkFailure(
"https://fakewebsite.com",
"GET",
DateTimeOffset.Now.ToUnixTimeMilliseconds(),
DateTimeOffset.Now.ToUnixTimeMilliseconds() + 100,
NetworkFailure.Unknown
);

Syntax

noticeNetworkFailure(String url, String httpMethod, int startTime, int endTime, NetworkFailure errorCode): void;

Description

Records network failures. If a network request fails, use this method to record details about the failures.

Parameters

Parameter

Type

Description

url

string

Required. The URL of the request.

httpMethod

string

Required. The HTTP method of the request.

startTime

int

Optional. The start time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

endTime

int

Optional. The end time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

errorCode

network failure

Required. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, SecureConnectionFailed.

Example

NewrelicMobile.instance.noticeNetworkFailure("https://cb6b02be-a319-4de5-a3b1-361de2564493.mock.pstmn.io/searchpage", "GET", 1000, 2000,'Test Network Failure', NetworkFailure.dnsLookupFailed);

Syntax

noticeNetworkFailure(url: string, httpMethod: string, startTime: number, endTime: number, failure: string): void;

Description

Records network failures. If a network request fails, use this method to record details about the failures. In most cases, place this call inside exception handlers, such as catch blocks.

Parameters

Parameter

Type

Description

url

string

Required. The URL of the request.

httpMethod

string

Required. The HTTP method of the request.

startTime

number

Optional. The start time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

endTime

number

Optional. The end time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

failure

string

Required. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, SecureConnectionFailed.

Example

NewRelic.noticeNetworkFailure('https://github.com', 'GET', Date.now(), Date.now(), NewRelic.NetworkFailure.BadURL);

Syntax

NoticeNetworkFailure(string url, string httpMethod, long startTime, long endTime, NetworkFailure failure)

Description

Records network failures. If a network request fails, use this method to record details about the failure.

Parameters

Parameter

Type

Description

url

string

Required. The URL of the request.

httpMethod

string

Required. The HTTP method of the request.

startTime

number

Optional. The start time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

endTime

number

Optional. The end time of the request in milliseconds since the epoch. startTime and endTime can be used as an alternative to timer.

failure

string

Optional. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: Unknown, BadURL, TimedOut, CannotConnectToHost, DNSLookupFailed, BadServerResponse, SecureConnectionFailed.

Example

CrossNewRelicClient.Current.NoticeNetworkFailure(
"https://fakewebsite.com",
"GET",
DateTimeOffset.Now.ToUnixTimeMilliseconds(),
DateTimeOffset.Now.ToUnixTimeMilliseconds() + 100,
NetworkFailure.Unknown
);
Copyright © 2024 New Relic Inc.

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