Skip to content

Latest commit

 

History

History
 
 

error_reporting

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Stackdriver Error Reporting

Open in Cloud Shell

This directory contains samples for setting up and using Stackdriver Error Reporting for PHP.

quickstart.php and src/report_error.php are simple command-line programs to demonstrate logging exceptions, errors, and PHP fatal errors to Stackdriver Error Reporting.

Installation

  1. To use this sample, you must first enable the Stackdriver Error Reporting API
  2. Next, Install dependencies via Composer:
    1. Run php composer.phar install (if composer is installed locally) or composer install (if composer is installed globally).
    composer install
    1. To use the gRPC PHP Extension, which will be more performant than REST/HTTP, install and enable the gRPC extension using PECL:
    pecl install grpc
  3. Create a service account in the Service Account section of the Cloud Console
  4. Download the JSON key file of the service account.
  5. Set GOOGLE_APPLICATION_CREDENTIALS environment variable to point to that file.
    export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_credentials.json

Running quickstart.php

Open quickstart.php in a text editor and replace the text YOUR_PROJECT_ID with your Project ID.

Run the samples:

php quickstart.php
Throwing a test exception. You can view the message at https://console.cloud.google.com/errors.

This example registers the Stackdriver exception handler using PHP exception handlers. View Stackdriver Error Reporting in the Cloud Console to see the logged exception.

Running src/report_error.php

This sample shows how to report an error by creating a ReportedErrorEvent. The ReportedErrorEvent object gives you more control over how the error appears and the details associated with it.

Run the sample:

$ php src/report_error.php YOUR_PROJECT_ID "This is a test message"
Reported an exception to Stackdriver

View Stackdriver Error Reporting in the Cloud Console to see the logged exception.