Advanced Bugsnag client usage for additional control over how and when Bugsnag sends notifications.
To create a fully customized Bugsnag integration, use the client constructor
instead of the default
// Configuration options used $config = new Bugsnag\Configuration("YOUR-API-KEY"); // Request resolver. The basic resolver resolves the current request. $resolver = new Bugsnag\BasicResolver(); // Customizable HTTP client $guzzle = new GuzzleHttp\Client(['base_uri' => Bugsnag\Client::ENDPOINT]); $bugsnag = new Bugsnag\Client($config, $resolver, $guzzle);
At this point, the
$bugsnag instance can be used directly to send error
and exception reports. Each of the constructor arguments can be modified as
needed to better suit your use case. Below are a few common examples.
If you require using a proxy or a custom timeout length when sending error
reports to Bugsnag, you can create a
Bugsnag\Client instance with a customized
HTTP client via Guzzle. The example in
creating a custom client would instead construct
$guzzle with additional parameters:
// Customizable HTTP client $guzzle = new GuzzleHttp\Client([ 'base_uri' => Bugsnag\Client::ENDPOINT, 'timeout' => 30, 'proxy' => 'tcp://localhost:8125', ]);
After constructing a custom Bugsnag client, you can register callbacks to collect
information about the state of the application when the error occurred. To
collect all of the metadata
by the default configuration in the
integration guide, use
A Bugsnag client can be modified using the configuration options provided. The transport method of an existing client is immutable; to change the transport method (such as the endpoint or proxy), construct a new Bugsnag client using the transport options.
For capturing errors that may occur before the client initializes, such as
E_PARSE, a file declaring a shutdown handler can be
registered before the application starts using the
auto_prepend_file option its
.ini configuration file.
This is not recommended for standard usage of any of the Bugsnag PHP notifiers due to the behaviour being inconsistent across different configuration files and the possibility of it being removed in newer versions of PHP, but it can be used to report difficult to track issues such as when an out of memory error occurs.
An example of using Bugsnag with an
.ini file can be found in the
examples folder of the main Bugsnag PHP notifier.