/** * Make a new bugsnag client instance. * * @param \Silex\Application $app * * @return \Bugsnag\Client */ 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); $stage = getenv('SYMFONY_ENV') ?: null; $client->setReleaseStage($stage === 'prod' ? 'production' : $stage); $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; }
/** * Setup the callbacks. * * @param \Bugsnag\Client $client * @param \Illuminate\Contracts\Container\Container $app * @param array $config * * @return void */ protected function setupCallbacks(Client $client, Container $app, array $config) { if (!isset($config['callbacks']) || $config['callbacks']) { $client->registerDefaultCallbacks(); $client->registerCallback(function (Report $report) use($app) { $tracker = $app->make(Tracker::class); if ($context = $tracker->context()) { $report->setContext($context); } if ($job = $tracker->get()) { $report->setMetaData(['job' => $job]); } }); } if (!isset($config['user']) || $config['user']) { $client->registerCallback(new CustomUser(function () use($app) { if ($user = $app->auth->user()) { return $user->toArray(); } })); } }