Advanced client configuration

How to construct a Bugsnag client manually when you need additional control over the transport and metadata sent.

Creating a custom client

To create a fully customized Bugsnag integration, use the client constructor instead of the default make helper:

// 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.

Customizing transport

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 the $guzzle with additional parameters:

// Customizable HTTP client
$guzzle = new GuzzleHttp\Client([
    'base_uri' => Bugsnag\Client::ENDPOINT,
    'timeout' => 30,
    'proxy' => 'tcp://localhost:8125',
]);

Customizing callbacks

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 automatically collected by the default configuration in the integration guide, use registerDefaultCallbacks:

$bugsnag->registerDefaultCallbacks();

Alternately, you can select callbacks to register individually from the callbacks bundled into the library or create your own.

Modifying existing clients

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.