bugsnag / bugsnag-symfony

BugSnag notifier for the Symfony PHP framework. Monitor and report errors in your Symfony apps.
https://docs.bugsnag.com/platforms/php/symfony
MIT License
43 stars 21 forks source link

Allow passing a Guzzle instance to Bugsnag #117

Closed imjoehaines closed 3 years ago

imjoehaines commented 3 years ago

Goal

This PR adds support for applications to pass a Guzzle instance to Bugsnag. This allows for configuring things like timeouts, proxy servers, add middleware etc...

We will read the service defined as bugsnag.guzzle if one exists, otherwise we create one internally as before. We also support passing the name of the service in Bugsnag configuration, so that users can pass a Guzzle instance that they already have configured

How to use

Register a service that returns a Guzzle client, e.g.

custom_guzzle:
    class: GuzzleHttp\ClientInterface
    factory: ['App\GuzzleFactory', create]

Then tell Bugsnag about it:

bugsnag:
    api_key: YOUR_KEY_HERE
    guzzle: custom_guzzle

You can also register your service as 'bugsnag.guzzle' to avoid having to tell Bugsnag about it explicitly, e.g.

bugsnag.guzzle:
    class: GuzzleHttp\ClientInterface
    factory: ['App\GuzzleFactory', create]

Then you can omit 'guzzle' from Bugsnag's configuration:

bugsnag:
    api_key: YOUR_KEY_HERE

These examples use a factory, but any service definition that results in a GuzzleHttp\ClientInterface will work, for example:

custom_guzzle:
    class: GuzzleHttp\Client
    arguments:
        - { timeout: 5 }

Testing