Configuration options

The BugSnag client object has several methods which help you customize the content of error reports, and how the reports are delivered. Some configuration options can be automatically populated by environment variables prior to calling Bugsnag\Client::make().

API key

You can set the BugSnag API key by setting the BUGSNAG_API_KEY environment variable, or passing it as the first parameter to the static make function:

Bugsnag\Client::make('YOUR-API-KEY-HERE');

You can also pass this as the first parameter when registering our error handler:

$bugsnag = Bugsnag\Handler::register('YOUR-API-KEY-HERE');

Finally, note that you can also pass a client instance to our error handler register method:

$bugsnag = Bugsnag\Handler::register(Bugsnag\Client::make('YOUR-API-KEY-HERE'));;

This setting is the only one which is required in order to use the notifier.

You can find your API key in Project Settings from your BugSnag dashboard.

App type

You can set the type of application executing the current code by using setAppType:

$bugsnag->setAppType('Mailer');

By default this is set to php_sapi_name().

App version

To track in which versions of your application each exception happens, set the app version:

$bugsnag->setAppVersion('1.2.3');

This will not be set by default.

Batch sending

If you’d like us to send the errors through to BugSnag when the PHP process shuts down, in order to prevent your app waiting on HTTP requests, this can be set to true. Setting it to false will mean the we send an HTTP request straight away for each error.

$bugsnag->setBatchSending(true);

By default, this is set to true.

You can also flush our error buffer by calling the flush function, causing any queued errors to be sent immediately:

$bugsnag->flush(true);

Build endpoint

You can changes the endpoint build notifications will delivered to.

$bugsnag->setBuildEndpoint('http://bugsnag-build.example.com');

By default, this is set to https://build.bugsnag.com.

Callbacks

Set a callback attached to the notification pipeline when notifying BugSnag of an error. You can use this to call your own error handling functions or customize the error report.

$bugsnag->registerCallback(function ($report) {
    // Inspect or modify the error report here
});

To cancel sending an error report, return false from the function.

Discard classes

Allows you to specify which events should be automatically discarded based on the class name of the exception.

Accepts both strings and regexes, and comparisons are case sensitive.

$bugsnag->setDiscardClasses([
    \Example\Exception::class,
    '/^Example\\.+/',
]);

PHP errors, such as notices and warnings, can be discarded with the errorReportingLevel option.

By default, no classes are discarded

Endpoint

You can change the BugSnag endpoint by setting the BUGSNAG_ENDPOINT environment variable, or passing it as the second parameter to the static make function:

Bugsnag\Client::make('YOUR-API-KEY-HERE', 'https://example.com');

By default, this is set to https://notify.bugsnag.com.

Error reporting level

Set the levels of PHP errors to report to BugSnag. If this is not set, the error_reporting option in php.ini or the value set using the error_reporting function will be used instead.

$bugsnag->setErrorReportingLevel(E_ALL & ~E_NOTICE);

See PHP’s error reporting documentation for allowed values.

Changing this option to include values not contained in error_reporting will result in a warning and errors with the excluded levels will be ignored.

Feature flags

Declare feature flag and experiment usage.

addFeatureFlag

Declare a single feature flag or experiment with variant as an optional second parameter.

$bugsnag->addFeatureFlag('Checkout button color', 'Blue')
$bugsnag->addFeatureFlag('New checkout flow')

addFeatureFlags

Declare multiple feature flags or experiments.

$bugsnag->addFeatureFlags([
    new \Bugsnag\FeatureFlag('Checkout button color', 'Blue'),
    new \Bugsnag\FeatureFlag('Special offer', 'Free Coffee'),
    new \Bugsnag\FeatureFlag('New checkout flow'),
])

If addFeatureFlags is called again, the new data will be merged with any existing feature flags with the newer variant values taking precedence.

See the Feature flags & experiments guide for more information.

Filters

Deprecated: Use redactedKeys instead.

Sets the strings to filter out from the metaData arrays before sending them to BugSnag. Use this if you want to ensure you don’t send sensitive data such as passwords, and credit card numbers to our servers. Any keys which contain these strings (ignoring case) will be filtered.

$bugsnag->setFilters(array_merge($bugsnag->getFilters(), ['credit_card']));

By default, this is set to be

['password', 'cookie', 'authorization', 'php-auth-user', 'php-auth-pw', 'php-auth-digest']

Hostname

If you would like to set the hostname of your server to something specific for you to identify it by, then you can call this method with your desired hostname.

$bugsnag->setHostname('your-hostname');

By default this is set to php_uname('n').

Max breadcrumbs

Sets the maximum number of breadcrumbs which will be stored. Once the threshold is reached, the oldest breadcrumbs will be deleted.

By default, 50 breadcrumbs are stored; this can be amended up to a maximum of 100.

$bugsnag->setMaxBreadcrumbs(100);

Memory limit increase

BugSnag will increase the PHP memory limit when your app runs out of memory to ensure events can be delivered. You can control the number of bytes BugSnag will increase the memory limit by with the setMemoryLimitIncrease method.

$bugsnag->setMemoryLimitIncrease(1024 * 1024 * 10); // 10 MiB

To disable this behaviour, pass null instead.

By default this is set to 5 MiB (1024 * 1024 * 5)

Metadata

Here you can set additional metadata to send with every bugsnag notification. By default, we merge your new metadata with anything already existing on the config object. You can pass false as the 2nd parameter to disable this behaviour.

$bugsnag->setMetaData([
    'account' => [
        'paying' => true,
        'name' => 'Acme Co'
    ]
]);

Project root

BugSnag marks stacktrace lines as in-project if they come from files inside your “project root”. This can be set by calling setProjectRoot on our client.

$bugsnag->setProjectRoot('/path/to/your/app/src');

If you wish to use regular expressions, you can call setProjectRootRegex on the client.

$bugsnag->setProjectRootRegex('/^\/path\/to\/your\/app\/src[\\/]?/i');

It also trims this path from the start of any filepath. If you want to change the strip path, see strip path.

This will not be set by default.

Proxies

If you’d like to set a proxy for us to use, you can set the HTTP_PROXY or HTTPS_PROXY variables for Guzzle.

Note that HTTP_PROXY is only available in cli, and if HTTPS_PROXY is present, it’ll replace HTTP_PROXY.

Redacted keys

Sets which values should be removed from any metadata before sending them to BugSnag. Use this if you want to ensure you don’t transmit sensitive data such as passwords and credit card numbers.

Any property whose key matches a redacted key will be filtered and replaced with [FILTERED].

Accepts both strings and regexes, and string comparisons are case insensitive.

$bugsnag->setRedactedKeys([
    'access_token', // case-insensitive: "access_token", "ACCESS_TOKEN", "AcCeSs_ToKeN"
    '/^cc_/'        // prefix match: "cc_number" "cc_cvv" "cc_expiry"
]);

By default, this is set to be

['password', 'cookie', 'authorization', 'php-auth-user', 'php-auth-pw', 'php-auth-digest']

The default values are set by the filters option.

Release stage

If you would like to distinguish between errors that happen in different stages of the application release process (development, production, etc) you can set the releaseStage that is reported to BugSnag.

$bugsnag->setReleaseStage('development');

By default, we set the release stage to production, and BugSnag is notified of errors that happen in any releaseStage.

If you would like to change which release stages notify BugSnag of errors you can call setNotifyReleaseStages.

$bugsnag->setNotifyReleaseStages(['development', 'production']);

If notify_release_stages are not set notifications will still be delivered.

Sending code

BugSnag automatically sends a small snippet of the code that crashed to help you diagnose even faster from within your dashboard. If you don’t want to send this snippet, you can call setSendCode:

$bugsnag->setSendCode(false);

By default, this is set to true.

Strip path

To make stacktraces clearer, BugSnag can trim file paths using the setStripPath function.

$bugsnag->setStripPath('/path/to/your/app');

If you wish to use regular expressions, you can call setStripPathRegex on the client.

$bugsnag->setStripPathRegex('/^\/path\/to\/your\/app[\\/]?/i');

If the project root is set, the strip path will be set automatically too.

This will not be set by default.