---
title: newrelic_set_error_group_callback (PHP agent API)
source: https://docs.newrelic.com/docs/apm/agents/php-agent/php-agent-api/newrelic_set_error_group_callback
---

## Syntax

```php
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

```php
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);
};
```
