PHP Error Monitoring

Monitoring for your site just got easier. With our powerful error monitoring service backed by our class leading APM solution, get back to what really matters by easily consolidating your error service and APM solution into one. When the error monitoring service is enabled, you will gain access to the context in which errors occur on your application. With our high fidelity overview charts as well as our detailed error tracing, you will gain insights into your app’s error trends as well as how these issues arose.

error monitoring overview page

Enabling Error Monitoring

Error Monitoring is available to apps using PHP 7.2+. It supports automatic exception handling for sym. To enable:

This adds a dependency on php-http/discovery. For this to work, you would already need an HTTP client installed, or install a compatible client.

1. Update to the latest version:

pip install scout-apm --upgrade

Error Monitoring was released in scout-apm version 7.0.0. Application monitoring must be enabled to use error monitoring.

2. Set the monitor and errors_enabled to True.

export SCOUT_MONITOR=True
export SCOUT_ERRORS_ENABLED=True

3. Laravel/Lumen: See instructions below based on version.

3. Symfony: No conguration required, but you will need to install something comparable to composer require php-http/httplug nyholm/psr7 to enable the PSR-18 HTTP Client auto discovery.

4. Deploy

Laravel 5/6/7

In order to capture errors, in your \App\Exceptions\Handler::report function in your application:

    /**
     * Report or log an exception.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report(Exception $exception)
    {
        $this->container->make(\Scoutapm\ScoutApmAgent::class)->recordThrowable($exception); // <-- add this line
        parent::report($exception);
    }

Laravel 8

In order to capture errors, in your \App\Exceptions\Handler::register function in your application:

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {
        $this->reportable(function (Throwable $e) {
            $this->container->make(ScoutApmAgent::class)->recordThrowable($e);
        });
    }

Lumen

In order to capture errors, in your \App\Exceptions\Handler::report function in your application:

    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Throwable  $exception
     * @return void
     *
     * @throws \Exception
     */
    public function report(Throwable $exception)
    {
        app(\Scoutapm\ScoutApmAgent::class)->recordThrowable($exception);
        parent::report($exception);
    }

Reporting Exceptions

Once the above configurations have been added, if an exception bubbles up to our middleware we will capture it.

However, if an error is caught, the error will never be received by our signal handler. To report this error to Scout use:

Ex:

try {
  throw new RuntimeException('something went wrong');
}
catch (RuntimeException $e) {
  $this->agent->recordThrowable($e);
  $this->agent->send();
}

Adding Context

Adding context to errors works exactly the same as adding context to web endpoints and background jobs.

If you have already added context to the endpoint or background job where the error has occurred, this context will be shown on the errors page.

Individual Error

To add context to an individual error, such as one that is caught:

try {
  throw new RuntimeException('something went wrong');
}
catch (RuntimeException $e) {
  $this->agent->addContext("Key", "Value");
  $this->agent->recordThrowable($e);
  $this->agent->send();
}

Visit our custom context section to learn more.

Error Notifications

Get notified of errors before your users notify you.

With our notification system, you can get error notifications sent to Slack, PagerDuty, Email, Webhooks, and more.

Slack Error Notification

Troubleshooting

If you receive an error, such as:

In ScoutErrorHandling.php line 66:
                                                         
  Class "Http\Discovery\Psr18ClientDiscovery" not found  

You need to resolve the HTTP discovery dependency, because your installed packages do not satisfy the requirement.

For example, if you are on PHP 7.1 and need Guzzle 6, composer require php-http/guzzle6-adapter nyholm/psr7 will fulfill the dependencies.

On PHP 7.2+, composer require guzzlehttp/guzzle:^7.0 is already compatible.

Not seeing errors?

Reach out to us at support@scoutapm.com for further support and troubleshooting assistance