protected function makeClient(Application $app)
    {
        try {
            $config = $app['bugsnag.options'];
        } catch (InvalidArgumentException $e) {
            $config = [];
        }

        $key = isset($config['api_key']) ? $config['api_key'] : getenv('BUGSNAG_API_KEY');

        $guzzle = Client::makeGuzzle(isset($config['endpoint']) ? $config['endpoint'] : null);

        $client = new Client(new Configuration($key), $app['bugsnag.resolver'], $guzzle);

        if (!isset($config['callbacks']) || $config['callbacks']) {
            $client->registerDefaultCallbacks();
        }

        if (!isset($config['user']) || $config['user']) {
            $this->setupUserDetection($client, $app);
        }

        $this->setupPaths($client, isset($config['strip_path']) ? $config['strip_path'] : null, isset($config['project_root']) ? $config['project_root'] : null);

        $env = getenv('SYMFONY_ENV') ?: null;
        $stage = isset($config['release_stage']) ? $config['release_stage'] : null;
        $client->setReleaseStage($stage ?: ($env === 'prod' ? 'production' : $env));
        $client->setHostname(isset($config['hostname']) ? $config['hostname'] : null);

        $client->setFallbackType('Console');
        $client->setAppType(isset($config['app_type']) ? $config['app_type'] : null);
        $client->setAppVersion(isset($config['app_version']) ? $config['app_version'] : null);
        $client->setBatchSending(isset($config['batch_sending']) ? $config['batch_sending'] : true);
        $client->setSendCode(isset($config['send_code']) ? $config['send_code'] : true);

        $client->setNotifier([
            'name' => 'Bugsnag Silex',
            'version' => static::VERSION,
            'url' => 'https://github.com/bugsnag/bugsnag-silex',
        ]);

        if (isset($config['notify_release_stages']) && is_array($config['notify_release_stages'])) {
            $client->setNotifyReleaseStages($config['notify_release_stages']);
        }
        if (isset($config['filters']) && is_array($config['filters'])) {
            $client->setFilters($config['filters']);
        }

        return $client;
    }