NOTE: This repository is part of Google Cloud PHP. Any
support requests, bug reports, or development contributions should be directed to
that project.
Stackdriver Error Reporting counts, analyzes and aggregates the crashes in your running cloud services.
Installation
To begin, install the preferred dependency manager for PHP, Composer.
Now install this component:
$ composer require google/cloud-error-reporting
This component supports both REST over HTTP/1.1 and gRPC. In order to take advantage of the benefits offered by gRPC (such as streaming methods)
please see our gRPC installation guide.
Authentication
Please see our Authentication guide for more information
on authenticating your client. Once authenticated, you'll be ready to start making requests.
Sample
Google\ApiCore\ApiException;
Google\Cloud\ErrorReporting\V1beta1\Client\ErrorGroupServiceClient;
Google\Cloud\ErrorReporting\V1beta1\ErrorGroup;
Google\Cloud\ErrorReporting\V1beta1\GetGroupRequest;
// Create a client.
$errorGroupServiceClient = new ErrorGroupServiceClient();
// Prepare the request message.
$request = (new GetGroupRequest())
->setGroupName($formattedGroupName);
// Call the API and handle any network failures.
try {
/** @var ErrorGroup $response */
$response = $errorGroupServiceClient->getGroup($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
The Stackdriver Error Reporting client provides APIs allowing you to easily configure your application to send errors and exceptions automatically to Stackdriver, or to manually report and manage errors and statistics.
Reporting errors from your application:
require 'vendor/autoload.php';
use Google\Cloud\ErrorReporting\Bootstrap;
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Core\Report\SimpleMetadataProvider;
$projectId = '[PROJECT]';
$service = '[SERVICE_NAME]';
$version = '[APP_VERSION]';
$logging = new LoggingClient();
$metadata = new SimpleMetadataProvider([], $projectId, $service, $version);
$psrLogger = $logging->psrLogger('error-log', [
'metadataProvider' => $metadata
]);
// Register the logger as a PHP exception and error handler.
// This will begin logging application exceptions and errors to Stackdriver.
Bootstrap::init($psrLogger);
Using the Error Reporting API:
require 'vendor/autoload.php';
use Google\Cloud\ErrorReporting\V1beta1\ReportErrorsServiceClient;
use Google\Cloud\ErrorReporting\V1beta1\ReportedErrorEvent;
$reportErrorsServiceClient = new ReportErrorsServiceClient();
$formattedProjectName = $reportErrorsServiceClient->projectName('[PROJECT]');
$event = new ReportedErrorEvent();
try {
$response = $reportErrorsServiceClient->reportErrorEvent($formattedProjectName, $event);
} finally {
$reportErrorsServiceClient->close();
}
Debugging
Please see our Debugging guide
for more information about the debugging tools.
Version
This component is considered beta. As such, it should be expected to be mostly
stable and we're working towards a release candidate. We will address issues
and requests with a higher priority.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [0.23.1 (latest)](/php/docs/reference/cloud-error-reporting/latest)\n- [0.23.0](/php/docs/reference/cloud-error-reporting/0.23.0)\n- [0.22.10](/php/docs/reference/cloud-error-reporting/0.22.10)\n- [0.21.1](/php/docs/reference/cloud-error-reporting/0.21.1)\n- [0.20.2](/php/docs/reference/cloud-error-reporting/0.20.2)\n- [0.19.12](/php/docs/reference/cloud-error-reporting/0.19.12) \n\nStackdriver Error Reporting for PHP\n===================================\n\n| **Beta**\n|\n| This library is covered by the [Pre-GA Offerings Terms](/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the [launch stage descriptions](/products#product-launch-stages).\n\u003e Idiomatic PHP client for [Stackdriver Error Reporting](https://cloud.google.com/error-reporting/).\n\n[](https://packagist.org/packages/google/cloud-error-reporting) [](https://packagist.org/packages/google/cloud-error-reporting)\n\n**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any\nsupport requests, bug reports, or development contributions should be directed to\nthat project.\n\nStackdriver Error Reporting counts, analyzes and aggregates the crashes in your running cloud services.\n\n### Installation\n\nTo begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/).\n\nNow install this component: \n\n $ composer require google/cloud-error-reporting\n\nThis component supports both REST over HTTP/1.1 and gRPC. In order to take advantage of the benefits offered by gRPC (such as streaming methods)\nplease see our [gRPC installation guide](https://cloud.google.com/php/grpc).\n\n### Authentication\n\nPlease see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information\non authenticating your client. Once authenticated, you'll be ready to start making requests.\n\n### Sample\n\n Google\\ApiCore\\ApiException;\n Google\\Cloud\\ErrorReporting\\V1beta1\\Client\\ErrorGroupServiceClient;\n Google\\Cloud\\ErrorReporting\\V1beta1\\ErrorGroup;\n Google\\Cloud\\ErrorReporting\\V1beta1\\GetGroupRequest;\n\n // Create a client.\n $errorGroupServiceClient = new ErrorGroupServiceClient();\n\n // Prepare the request message.\n $request = (new GetGroupRequest())\n -\u003esetGroupName($formattedGroupName);\n\n // Call the API and handle any network failures.\n try {\n /** @var ErrorGroup $response */\n $response = $errorGroupServiceClient-\u003egetGroup($request);\n printf('Response data: %s' . PHP_EOL, $response-\u003eserializeToJsonString());\n } catch (ApiException $ex) {\n printf('Call failed with message: %s' . PHP_EOL, $ex-\u003egetMessage());\n }\n\nThe Stackdriver Error Reporting client provides APIs allowing you to easily configure your application to send errors and exceptions automatically to Stackdriver, or to manually report and manage errors and statistics.\n\n#### Reporting errors from your application:\n\n require 'vendor/autoload.php';\n\n use Google\\Cloud\\ErrorReporting\\Bootstrap;\n use Google\\Cloud\\Logging\\LoggingClient;\n use Google\\Cloud\\Core\\Report\\SimpleMetadataProvider;\n\n $projectId = '[PROJECT]';\n $service = '[SERVICE_NAME]';\n $version = '[APP_VERSION]';\n\n $logging = new LoggingClient();\n $metadata = new SimpleMetadataProvider([], $projectId, $service, $version);\n $psrLogger = $logging-\u003epsrLogger('error-log', [\n 'metadataProvider' =\u003e $metadata\n ]);\n\n // Register the logger as a PHP exception and error handler.\n // This will begin logging application exceptions and errors to Stackdriver.\n Bootstrap::init($psrLogger);\n\n#### Using the Error Reporting API:\n\n require 'vendor/autoload.php';\n\n use Google\\Cloud\\ErrorReporting\\V1beta1\\ReportErrorsServiceClient;\n use Google\\Cloud\\ErrorReporting\\V1beta1\\ReportedErrorEvent;\n\n $reportErrorsServiceClient = new ReportErrorsServiceClient();\n $formattedProjectName = $reportErrorsServiceClient-\u003eprojectName('[PROJECT]');\n $event = new ReportedErrorEvent();\n\n try {\n $response = $reportErrorsServiceClient-\u003ereportErrorEvent($formattedProjectName, $event);\n } finally {\n $reportErrorsServiceClient-\u003eclose();\n }\n\n### Debugging\n\nPlease see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md)\nfor more information about the debugging tools.\n\n### Version\n\nThis component is considered beta. As such, it should be expected to be mostly\nstable and we're working towards a release candidate. We will address issues\nand requests with a higher priority.\n\n### Next Steps\n\n1. Understand the [official documentation](https://cloud.google.com/error-reporting/docs/).\n2. Take a look at [in-depth usage samples](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/error_reporting)."]]