2017 © Pedro Peláez
 

library phpbrake

Airbrake exception and error notifier for PHP

image

airbrake/phpbrake

Airbrake exception and error notifier for PHP

  • Thursday, July 5, 2018
  • by gary_rafferty
  • Repository
  • 16 Watchers
  • 31 Stars
  • 229,879 Installations
  • PHP
  • 22 Dependents
  • 3 Suggesters
  • 21 Forks
  • 1 Open issues
  • 33 Versions
  • 15 % Grown

The README.md

, (*1)

PHPBrake

Build Status, (*2)

Features

PHPBrake is the official Airbrake PHP error notifier. PHPBrake supports PHP 8.2 and higher. PHPBrake includes many useful features that give you control over when and what you send to Airbrake, you can:, (*3)

Installation

composer require airbrake/phpbrake

Quickstart

// Create new Notifier instance.
$notifier = new Airbrake\Notifier([
    'projectId' => 12345, // FIX ME
    'projectKey' => 'abcdefg' // FIX ME
]);

// Set global notifier instance.
Airbrake\Instance::set($notifier);

// Register error and exception handlers.
$handler = new Airbrake\ErrorHandler($notifier);
$handler->register();

// Somewhere in the app...
try {
    throw new Exception('hello from phpbrake');
} catch(Exception $e) {
    Airbrake\Instance::notify($e);
}

API

Notifier API consists of 4 methods: - buildNotice - builds Airbrake notice. - sendNotice - sends notice to Airbrake. - notify - shortcut for buildNotice and sendNotice. - addFilter - adds filter that can modify and/or filter notices., (*4)

Adding custom data to the notice

$notifier->addFilter(function ($notice) {
    $notice['context']['environment'] = 'production';
    return $notice;
});

Filtering sensitive data from the notice

$notifier->addFilter(function ($notice) {
    if (isset($notice['params']['password'])) {
        $notice['params']['password'] = 'FILTERED';
    }
    return $notice;
});

Ignoring specific exceptions

$notifier->addFilter(function ($notice) {
    if ($notice['errors'][0]['type'] == 'MyExceptionClass') {
        // Ignore this exception.
        return null;
    }
    return $notice;
});

Add user data to the notice

$notifier->addFilter(function ($notice) {
    $notice['context']['user']['name'] = 'Avocado Jones';
    $notice['context']['user']['email'] = 'AJones@guacamole.com';
    $notice['context']['user']['id'] = 12345;
    return $notice;
});

Setting severity

Severity allows categorizing how severe an error is. By default, it's set to error. To redefine severity, simply overwrite context/severity of a notice object. For example:, (*5)

$notice = $notifier->buildNotice($e);
$notice['context']['severity'] = 'critical';
$notifier->sendNotice($notice);

Error handler

Notifier can handle PHP errors, uncaught exceptions and shutdown. You can register appropriate handlers using following code:, (*6)

$handler = new Airbrake\ErrorHandler($notifier);
$handler->register();

Under the hood $handler->register does following:, (*7)

set_error_handler([$this, 'onError'], error_reporting());
set_exception_handler([$this, 'onException']);
register_shutdown_function([$this, 'onShutdown']);

Laravel integration

See https://github.com/TheoKouzelis/laravel-airbrake, (*8)

Symfony integration

See https://github.com/aminin/airbrake-bundle, (*9)

CakePHP 3.x integration

See https://gist.github.com/mauriciovillalobos/01a97f9ee6179ad70b17d54f37cc5010, (*10)

Zend Framework integration

See https://github.com/FrankHouweling/zend-airbrake, (*11)

Monolog integration

$log = new Monolog\Logger('billing');
$log->pushHandler(new Airbrake\MonologHandler($notifier));

$log->addError('charge failed', ['client_id' => 123]);

Extra configuration options

appVersion

The version of your application that you can pass to differentiate exceptions between multiple versions. It's not set by default., (*12)

$notifier = new Airbrake\Notifier([
    // ...
    'appVersion' => '1.2.3',
    // ...
]);

host

By default, it is set to api.airbrake.io. A host is a web address containing a scheme ("http" or "https"), a host and a port. You can omit the port (80 will be assumed) and the scheme ("https" will be assumed)., (*13)

$notifier = new Airbrake\Notifier([
    // ...
    'host' => 'errbit.example.com', // put your errbit host here
    // ...
]);

remoteConfig

Configures the remote configuration feature. Every 10 minutes the notifier will make a GET request to Airbrake servers to fetching a JSON document containing configuration settings for your project. The notifier will apply these new settings at runtime. By default, it is enabled., (*14)

To disable this feature, configure your notifier with:, (*15)

$notifier = new Airbrake\Notifier([
    // ...
    'remoteConfig' => false,
    // ...
]);

Note: it is not recommended to disable this feature. It might negatively impact how your notifier works. Please use this option with caution., (*16)

rootDirectory

Configures the root directory of your project. Expects a String or a Pathname, which represents the path to your project. Providing this option helps us to filter out repetitive data from backtrace frames and link to GitHub files from our dashboard., (*17)

$notifier = new Airbrake\Notifier([
    // ...
    'rootDirectory' => '/var/www/project',
    // ...
]);

environment

Configures the environment the application is running in. Helps the Airbrake dashboard to distinguish between exceptions occurring in different environments. By default, it's not set., (*18)

$notifier = new Airbrake\Notifier([
    // ...
    'environment' => 'staging',
    // ...
]);

httpClient

Configures the underlying http client that must implement GuzzleHttp\ClientInterface., (*19)

// Supply your own client.
$client = new Airbrake\Http\GuzzleClient(
    new GuzzleHttp\Client(['timeout' => 3])
);

$notifier = new Airbrake\Notifier([
    // ...
    'httpClient' => $client,
    // ...
]);

Filtering keys

With keysBlocklist option you can specify list of keys containing sensitive information that must be filtered out, e.g.:, (*20)

$notifier = new Airbrake\Notifier([
    // ...
    'keysBlocklist' => ['/secret/i', '/password/i'],
    // ...
]);

Running tests

Run via docker:, (*21)

docker compose run tests

Or run locally, (*22)

composer install
vendor/bin/phpunit

PHPDoc

composer require phpdocumentor/phpdocumentor
vendor/bin/phpdoc -d src
firefox output/index.html

Contact

In case you have a problem, question or a bug report, feel free to:, (*23)

License

PHPBrake is licensed under The MIT License (MIT)., (*24)

The Versions

05/07 2018

dev-master

9999999-dev https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

05/07 2018

v0.6.0

0.6.0.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

05/07 2018

dev-feature/keys-blacklist

dev-feature/keys-blacklist https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

05/07 2018

dev-fix/source-version

dev-fix/source-version https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

22/03 2018

dev-feature/git-revision

dev-feature/git-revision https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

15/03 2018

v0.5.3

0.5.3.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

29/01 2018

v0.5.2

0.5.2.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

29/01 2018

dev-fix/backtrace-error-handler

dev-fix/backtrace-error-handler https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

21/11 2017

v0.5.1

0.5.1.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

11/09 2017

v0.4.1

0.4.1.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

07/09 2017

v0.4.0

0.4.0.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

logging exception airbrake error notifier

13/06 2017

v0.3.1

0.3.1.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

01/06 2017

v0.3.0

0.3.0.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

11/05 2017

v0.2.4

0.2.4.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

14/03 2017

v0.2.3

0.2.3.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

25/01 2017

v0.2.2

0.2.2.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

04/01 2017

v0.2.1

0.2.1.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

21/07 2016

v0.2.0

0.2.0.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

13/07 2016

v0.1.2

0.1.2.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

21/03 2016

v0.1.1

0.1.1.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

16/03 2016

v0.1.0

0.1.0.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

10/01 2016

v0.0.12

0.0.12.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

05/10 2015

v0.0.11

0.0.11.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

02/10 2015

v0.0.10

0.0.10.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

01/10 2015

v0.0.9

0.0.9.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

30/09 2015

v0.0.8

0.0.8.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

logging exception airbrake error notifier

27/08 2015

v0.0.7

0.0.7.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

logging exception airbrake error notifier

14/08 2015

v0.0.6

0.0.6.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Development Requires

logging exception airbrake error notifier

30/07 2015

v0.0.5

0.0.5.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Development Requires

logging exception airbrake error notifier

22/07 2015

v0.0.4

0.0.4.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Development Requires

logging exception airbrake error notifier

22/07 2015

v0.0.3

0.0.3.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Development Requires

logging exception airbrake error notifier

16/07 2015

v0.0.2

0.0.2.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Development Requires

logging exception airbrake error notifier

16/07 2015

v0.0.1

0.0.1.0 https://airbrake.io

Airbrake exception and error notifier for PHP

  Sources   Download

MIT

The Development Requires

logging exception airbrake error notifier