Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto on session tracking #343

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
"email": "[email protected]"
}
],
"repositories": [
Cawllec marked this conversation as resolved.
Show resolved Hide resolved
{
"type": "git",
"url": "https://github.com/bugsnag/bugsnag-php"
},
{
"type": "git",
"url": "https://github.com/bugsnag/bugsnag-psr-logger"
}
],
"require": {
"php": ">=5.5",
"illuminate/contracts": "^5.0",
"illuminate/support": "^5.0",
"bugsnag/bugsnag": "^3.15.0",
"bugsnag/bugsnag-psr-logger": "^1.4",
"bugsnag/bugsnag": "dev-aost/base-changes",
"bugsnag/bugsnag-psr-logger": "dev-cawllec/aost-base",
"monolog/monolog": "^1.12"
},
"require-dev": {
Expand Down
22 changes: 19 additions & 3 deletions config/bugsnag.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,27 @@

'batch_sending' => env('BUGSNAG_BATCH_SENDING'),

/*
|--------------------------------------------------------------------------
| Notify Endpoint
|--------------------------------------------------------------------------
|
| Set what server the Bugsnag notifier should send errors to. By default
| this is set to 'https://notify.bugsnag.com', but for Bugsnag Enterprise
| this should be the URL to your Bugsnag instance.
|
*/

'notify_endpoint' => env('BUGSNAG_NOTIFY_ENDPOINT'),

/*
|--------------------------------------------------------------------------
| Endpoint
|--------------------------------------------------------------------------
|
| Deprecated: Use the 'notify_endpoint' or BUGSNAG_NOTIFY_ENDPOINT
| environment variable instead
|
| Set what server the Bugsnag notifier should send errors to. By default
| this is set to 'https://notify.bugsnag.com', but for Bugsnag Enterprise
| this should be the URL to your Bugsnag instance.
Expand Down Expand Up @@ -247,15 +263,15 @@
| Auto Capture Sessions
|--------------------------------------------------------------------------
|
| Enable this to start tracking sessions and deliver them to Bugsnag.
| Disable this to stop automatically tracking sessions.
|
*/

'auto_capture_sessions' => env('BUGSNAG_CAPTURE_SESSIONS', false),
'auto_capture_sessions' => env('BUGSNAG_CAPTURE_SESSIONS', true),

/*
|--------------------------------------------------------------------------
| Sessions Endpoint
| Session Endpoint
|--------------------------------------------------------------------------
|
| Sets a url to send tracked sessions to.
Expand Down
2 changes: 2 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
File.open('composer.json', 'r') do |source|
parsed_composer = JSON.parse source.read
requirements = parsed_composer["require"]
repositories = parsed_composer["repositories"]
File.open('features/fixtures/laravel/composer.json.template', 'r') do |template|
parsed_template = JSON.parse template.read
parsed_template["repositories"][0]["package"]["require"] = requirements
parsed_template["repositories"].concat(repositories)
File.open('features/fixtures/laravel/composer.json', 'w') do |target|
target.write(JSON.pretty_generate(parsed_template))
end
Expand Down
27 changes: 14 additions & 13 deletions src/BugsnagServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Bugsnag\PsrLogger\BugsnagLogger;
use Bugsnag\PsrLogger\MultiLogger as BaseMultiLogger;
use Bugsnag\Report;
use Bugsnag\Utils;
use Illuminate\Auth\GenericUser;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
Expand Down Expand Up @@ -182,7 +183,13 @@ public function register()
{
$this->app->singleton('bugsnag', function (Container $app) {
$config = $app->config->get('bugsnag');
$client = new Client(new Configuration($config['api_key']), new LaravelResolver($app), $this->getGuzzle($config));
$client = new Client(new Configuration($config['api_key']), new LaravelResolver($app));
$client->setGuzzleClient($this->getGuzzle($config));

if (($config['endpoint'] || $config['notify_endpoint'])) {
$notifyEndpoint = $config['notify_endpoint'] ?: $config['endpoint'];
$client->setEndpoints($notifyEndpoint, $config['session_endpoint']);
}

$this->setupCallbacks($client, $app, $config);
$this->setupPaths($client, $app->basePath(), $app->path(), isset($config['strip_path']) ? $config['strip_path'] : null, isset($config['project_root']) ? $config['project_root'] : null);
Expand Down Expand Up @@ -212,8 +219,7 @@ public function register()
}

if (isset($config['auto_capture_sessions']) && $config['auto_capture_sessions']) {
$endpoint = isset($config['session_endpoint']) ? $config['session_endpoint'] : null;
$this->setupSessionTracking($client, $endpoint, $this->app->events);
$this->setupSessionTracking($client, $this->app->events);
}

if (isset($config['build_endpoint'])) {
Expand Down Expand Up @@ -260,21 +266,19 @@ public function register()
*
* @param array $config
*
* @return \GuzzleHttp\ClientInterface
* @return \GuzzleHttp\ClientInterface|null
*/
protected function getGuzzle(array $config)
{
$options = [];

if (isset($config['proxy']) && $config['proxy']) {
if (isset($config['proxy']['http']) && php_sapi_name() != 'cli') {
unset($config['proxy']['http']);
}

$options['proxy'] = $config['proxy'];
return Utils::makeGuzzle(['proxy' => $config['proxy']]);
}

return Client::makeGuzzle(isset($config['endpoint']) ? $config['endpoint'] : null, $options);
return null;
}

/**
Expand Down Expand Up @@ -364,16 +368,13 @@ protected function setupPaths(Client $client, $base, $path, $strip, $project)
* Setup session tracking.
*
* @param \Bugsnag\Client $client
* @param string $endpoint
* @param array $events
*
* @return void
*/
protected function setupSessionTracking(Client $client, $endpoint, $events)
protected function setupSessionTracking(Client $client, $events)
{
$client->setAutoCaptureSessions(true);
if (!is_null($endpoint)) {
$client->setSessionEndpoint($endpoint);
}
$sessionTracker = $client->getSessionTracker();

$sessionStorage = function ($session = null) {
Expand Down