• /
  • EnglishEspañol日本語한국어Português
  • Log inStart now

newrelic_set_error_group_callback (PHP agent API)

Syntax

newrelic_set_error_group_callback($callback)

Group errors with your own custom-defined fingerprinting callback function.

Requirements

Agent version 10.12 or higher.

Description

This API allows a user to register a custom callback function with the PHP agent that will be called when the application encounters an error.

The callback will provide two PHP arrays from the agent - one containing transaction data, and another containing error data.

Using the provided context information, the callback must return a non-empty string based on user-defined logic that will serve as the error group name displayed in the Errors Inbox UI.

Important

  • When there are multiple calls to this function in a single transaction, the PHP agent retains the callback from the last call only.

  • Callbacks are registered on a per-request basis. This API should be called in a code path that is guaranteed to be executed for each request, or the callback will not be invoked.

  • It is highly recommended to keep your callback function as minimal as possible. CPU-intensive callbacks (such as database calls) or other complex logic will result in performance impacts on your application.

Parameters

This API accepts a single function-type callback as an argument. The provided callback must accept 2 parameters.

API Parameter

Description

$callback (function)

Required. Provide a callback function that will be registered with the PHP agent.

Callback Parameters

Description

$transaction_data (array)

Required. An array of transaction data provided to your callback by the PHP agent.

$error_data (array)

Required. An array of error data provided to your callback by the PHP agent.

Array key/value pairs

$transaction_data - PHP agent transaction data provided to your callback

Key

Value

"request_uri"

(string) Request URI

"path"

(string) Filepath

"method"

(string) HTTP method (GET, POST, etc.)

"status_code"

(int) HTTP status code (200, 404, etc.)

$error_data - PHP agent error data provided to your callback

Key

Value

"klass"

(string) Class name

"message"

(string) Error message

"file"

(string) Filepath

"stack"

(string) JSON error strack trace

Important

  • Not all keys are guaranteed to contain values. This is highly dependent on the user application and the nature of the error.
  • Array keys will always be set regardless of whether or not they contain empty values.

Return values

API returns true if the callback is registered successfully, otherwise false.

Examples

if (extension_loaded('newrelic')) { // Ensure PHP agent is available
$callback = function(array $transaction_data, array $error_data)
{
$fingerprint = "";
//
// Add custom code to parse array data
//
// Example code
if ($error_data["klass"] == "E_USER_ERROR") {
$fingerprint = "USER ERROR";
};
return $fingerprint; // Non-empty string error group name
};
newrelic_set_error_group_callback($callback);
};
Copyright © 2024 New Relic Inc.

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