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

NoticeError (.NET agent API)

Overloads

Notice an error and report to New Relic, along with optional custom attributes.

NewRelic.Api.Agent.NewRelic.NoticeError(Exception $exception);
NewRelic.Api.Agent.NewRelic.NoticeError(Exception $exception, IDictionary<TKey, TValue> $attributes);
NewRelic.Api.Agent.NewRelic.NoticeError(string $error_message, IDictionary<TKey, TValue> $attributes);
NewRelic.Api.Agent.NewRelic.NoticeError(string $error_message, IDictionary<TKey, TValue> $attributes, bool $is_expected);

Requirements

This API call is compatible with:

  • All agent versions
  • All app types

Description

Notice an error and report it to New Relic along with optional custom attributes. For each transaction, the agent only retains the exception and attributes from the first call to NoticeError(). You can pass an actual exception, or pass a string to capture an arbitrary error message.

If this method is invoked within a transaction, the agent reports the exception within the parent transaction. If it is invoked outside of a transaction, the agent creates an error trace and categorizes the error in the New Relic UI as a NewRelic.Api.Agent.NoticeError API call. If invoked outside of a transaction, the NoticeError() call will not contribute to the error rate of an application.

The agent adds the attributes only to the traced error; it does not send them to New Relic. For more information, see AddCustomAttribute().

Errors reported with this API are still sent to New Relic when they are reported within a transaction that results in an HTTP status code, such as a 404, that is configured to be ignored by agent configuration. For more information, see our documentation about managing errors in APM.

Review the sections below to see examples of how to use this call.

NoticeError(Exception)

NewRelic.Api.Agent.NewRelic.NoticeError(Exception $exception)

Parameter

Description

$exception

Exception

Required. The Exception you want to instrument. Only the first 10,000 characters from the stack trace are retained.

NoticeError(Exception, IDictionary)

NewRelic.Api.Agent.NewRelic.NoticeError(Exception $exception, IDictionary<TKey, TValue> $attributes)

Parameter

Description

$exception

Exception

Required. The Exception you want to instrument. Only the first 10,000 characters from the stack trace are retained.

$attributes

IDictionary<TKey, TValue>

Specify key/value pairs of attributes to annotate the error message. The TKey must be a string, the TValue can be a string or object.

NoticeError(String, IDictionary)

NewRelic.Api.Agent.NewRelic.NoticeError(string $error_message, IDictionary<TKey, TValue> $attributes)

Parameter

Description

$error_message

string

Required. Specify a string to report to New Relic as though it's an exception. This method creates both error events and error traces. Only the first 1023 characters are retained in error events, while error traces retain the full message.

$attributes

IDictionary<TKey, TValue>

Required (can be null). Specify key/value pairs of attributes to annotate the error message. The TKey must be a string, the TValue can be a string or object, to send no attributes, pass null.

NoticeError(String, IDictionary, bool)

NewRelic.Api.Agent.NewRelic.NoticeError(string $error_message, IDictionary<TKey, TValue> $attributes, bool $is_expected)

Parameter

Description

$error_message

string

Required. Specify a string to report to New Relic as though it's an exception. This method creates both error events and error traces. Only the first 1023 characters are retained in error events, while error traces retain the full message.

$attributes

IDictionary<TKey, TValue>

Required (can be null). Specify key/value pairs of attributes to annotate the error message. The TKey must be a string, the TValue can be a string or object, to send no attributes, pass null.

$is_expected

bool

Mark error as expected so that it won't affect Apdex score and error rate.

Pass an exception without custom attributes

try
{
string ImNotABool = "43";
bool.Parse(ImNotABool);
}
catch (Exception ex)
{
NewRelic.Api.Agent.NewRelic.NoticeError(ex);
}

Pass an exception with custom attributes

try
{
string ImNotABool = "43";
bool.Parse(ImNotABool);
}
catch (Exception ex)
{
var errorAttributes = new Dictionary<string, string>() {{"foo", "bar"},{"baz", "luhr"}};
NewRelic.Api.Agent.NewRelic.NoticeError(ex, errorAttributes);
}

Pass an error message string with custom attributes

try
{
string ImNotABool = "43";
bool.Parse(ImNotABool);
}
catch (Exception ex)
{
var errorAttributes = new Dictionary<string, string>{{"foo", "bar"},{"baz", "luhr"}};
NewRelic.Api.Agent.NewRelic.NoticeError("String error message", errorAttributes);
}

Pass an error message string without custom attributes

try
{
string ImNotABool = "43";
bool.Parse(ImNotABool);
}
catch (Exception ex)
{
NewRelic.Api.Agent.NewRelic.NoticeError("String error message", null);
}

Pass an error message string and mark it as expected

try
{
string ImNotABool = "43";
bool.Parse(ImNotABool);
}
catch (Exception ex)
{
NewRelic.Api.Agent.NewRelic.NoticeError("String error message", null, true);
}
Copyright © 2024 New Relic Inc.

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