v-rie / honeybadger-php

PHP library for reporting errors to honeybadger.io

Home Page:https://www.honeybadger.io/for/php

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Honeybadger PHP library

Latest Version on Packagist Total Downloads Build Status Quality Score Maintainability Test Coverage StyleCI

This is the client library for integrating apps with the ⚡ Honeybadger Exception Notifier for PHP.

Framework Integrations

Installation

You can install the package via composer:

composer require honeybadger-io/honeybadger-php

Usage

Send Exception Notification

$honeybadger = Honeybadger::new([
    'api_key' => 'abc123'
]);

try {
    throw new Exception('Whoops!');
} catch (Exception $e) {
    // You can optionally include your own
    // \Symfony\Component\HttpFoundation\Request::class request.
    $honeybadger->notify($e, $app->request());
}

Sending Custom Notifications

See the Honeybadger API documentation. All fields except the notifier are valid.

$honeybadger = Honeybadger::new([
    'api_key' => 'abc123'
]);

$honeybadger->customNotification([
    'title'   => 'Special Error',
    'message' => 'Special Error: a special error has occurred',
]);

Adding Context

$honeybadger->context('foo', 'bar');

Send Application Check-in

$honeybadger = Honeybadger::new([
    'api_key' => 'abc123'
]);

$honeybadger->checkin('1234');

Configuration

Default values are listed below.

[
    // Honeybadger API Key
    'api_key' => null,

    'environment' => [
        // Environment keys to filter before the payload sent to Honeybadger (see Environment Whitelist)
        'filter' => [],

        // Additional environment keys to include (see Environment Whitelist)
        'include' => [],
    ],

    'request' => [
        // Request keys to filter before the payload sent to Honeybadger
        'filter' => [
            'password',
            'password_confirmation'
        ],
    ],

    // Application version
    'version' => '',

    // System hostname
    'hostname' => gethostname(),

    // Project root (/var/www)
    'project_root' => '',

    // Application environment name
    'environment_name' => 'production',

    'handlers' => [
        // Enable global exception handler
        'exception' => true,

        // Enable global error handler
        'error' => true,
    ],
    'client' => [
        // Request timeout length (default: indefinite)
        'timeout' => 0,

        // Request proxy settings
        'proxy' => [
            // Use this proxy with 'http' (tcp://username:password@localhost:8125)
            'http'  => '',

            // Use this proxy with 'https' (tcp://username:password@localhost:8125)
            'https' => '',
        ],
    ],

    // Exclude exceptions from being reported
    'excluded_exceptions' => [],
]

Environment Whitelist

Note: All HTTP_* keys are included by default.

All whitelisted keys
'PHP_SELF'
'argv'
'argc'
'GATEWAY_INTERFACE'
'SERVER_ADDR'
'SERVER_NAME'
'SERVER_SOFTWARE'
'SERVER_PROTOCOL'
'REQUEST_METHOD'
'REQUEST_TIME'
'REQUEST_TIME_FLOAT'
'QUERY_STRING'
'DOCUMENT_ROOT'
'HTTPS'
'REMOTE_ADDR'
'REMOTE_HOST'
'REMOTE_PORT'
'REMOTE_USER'
'REDIRECT_REMOTE_USER'
'SCRIPT_FILENAME'
'SERVER_ADMIN'
'SERVER_PORT'
'SERVER_SIGNATURE'
'PATH_TRANSLATED'
'SCRIPT_NAME'
'REQUEST_URI'
'PHP_AUTH_DIGEST'
'PHP_AUTH_USER'
'PHP_AUTH_PW'
'AUTH_TYPE'
'PATH_INFO'
'ORIG_PATH_INFO'
'APP_ENV'

Exceptions

If there is an error contacting Honeybadger a \Honeybadger\Exceptions\ServiceException::class will be thrown with a relevant exception message.

Testing

composer test

Code Style

In addition to the php-cs-fixer rules, StyleCI will apply the Laravel preset.

composer styles:lint
composer styles:fix

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email oss@tjmiller.co instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

PHP library for reporting errors to honeybadger.io

https://www.honeybadger.io/for/php

License:MIT License


Languages

Language:PHP 100.0%