Syntax
NewRelic.Api.Agent.NewRelic.SetErrorGroupCallback(Func<IReadOnlyDictionary<string,object>, string> errorGroupCallback);
Provide a callback method that takes an IReadOnlyDictionary<string,object>
of attribute data, and returns an error group name.
Requirements
This API call is compatible with:
- Agent versions >= 10.9.0
- All app types
Description
Set a callback method that the agent will use to determine the error group name for error events and traces. This name is used in the Errors Inbox to group errors into logical groups.
The callback method must accept a single argument of type IReadOnlyDictionary<string,object>
, and return a string (the error group name). The IReadOnlyDictionary
is a collection of attribute data associated with each error event, including custom attributes.
The exact list of attributes available for each error will vary depending on:
- What application code generated the error
- Agent configuration settings
- Whether any custom attributes were added
However, the following attributes should always exist:
error.class
error.message
stack_trace
transactionName
request.uri
error.expected
An empty string may be returned for the error group name when the error can't be assigned to a logical error group.
Parameters
Parameter | Description |
---|---|
Func<IReadOnlyDictionary<string,object>,string> | The callback to determine the error group name based on attribute data. |
Examples
Group errors by error class name:
Func<IReadOnlyDictionary<string, object>, string> errorGroupCallback = (attributes) => { string errorGroupName = string.Empty; if (attributes.TryGetValue("error.class", out var errorClass)) { if (errorClass.ToString() == "System.ArgumentOutOfRangeException" || errorClass.ToString() == "System.ArgumentNullException") { errorGroupName = "ArgumentErrors"; } else { errorGroupName = "OtherErrors"; } } return errorGroupName;};
NewRelic.Api.Agent.NewRelic.SetErrorGroupCallback(errorGroupCallback);
Group errors by transaction name:
Func<IReadOnlyDictionary<string, object>, string> errorGroupCallback = (attributes) => { string errorGroupName = string.Empty; if (attributes.TryGetValue("transactionName", out var transactionName)) { if (transactionName.ToString().IndexOf("WebTransaction/MVC/Home") != -1) { errorGroupName = "HomeControllerErrors"; } else { errorGroupName = "OtherControllerErrors"; } } return errorGroupName;};
NewRelic.Api.Agent.NewRelic.SetErrorGroupCallback(errorGroupCallback);