Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
72 changes: 47 additions & 25 deletions DependencyInjection/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,35 @@ class ClientFactory
*/
protected $filters;

/**
* The exception excepts to not report.
*
* @var string[]|null
*/
protected $excepts;

/**
* Create a new client factory instance.
*
* @param \Bugsnag\BugsnagBundle\Request\SymfonyResolver $resolver
* @param \Bugsnag\BugsnagBundle\Request\SymfonyResolver $resolver
* @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface|null $tokens
* @param \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface|null $checker
* @param string|null $key
* @param string|null $endpoint
* @param bool $callbacks
* @param bool $user
* @param string|null $type
* @param string|null $version
* @param bool $batch
* @param string|null $hostname
* @param bool $code
* @param string|null $strip
* @param string|null $project
* @param string|null $root
* @param string|null $stage
* @param string[]|null $stages
* @param string[]|null $filters
* @param \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface|null $checker
* @param string|null $key
* @param string|null $endpoint
* @param bool $callbacks
* @param bool $user
* @param string|null $type
* @param string|null $version
* @param bool $batch
* @param string|null $hostname
* @param bool $code
* @param string|null $strip
* @param string|null $project
* @param string|null $root
* @param string|null $stage
* @param string[]|null $stages
* @param string[]|null $filters
* @param string[]|null $excepts
*
* @return void
*/
Expand All @@ -181,8 +189,10 @@ public function __construct(
$root = null,
$stage = null,
array $stages = null,
array $filters = null
) {
array $filters = null,
array $excepts = null
)
{
$this->resolver = $resolver;
$this->tokens = $tokens;
$this->checker = $checker;
Expand All @@ -201,6 +211,7 @@ public function __construct(
$this->stage = $stage;
$this->stages = $stages;
$this->filters = $filters;
$this->excepts = $excepts;
}

/**
Expand Down Expand Up @@ -254,9 +265,9 @@ public function make()
/**
* Setup user detection.
*
* @param \Bugsnag\Client $client
* @param \Bugsnag\Client $client
* @param \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokens
* @param \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface $checker
* @param \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface $checker
*
* @return void
*/
Expand All @@ -275,17 +286,17 @@ protected function setupUserDetection(Client $client, TokenStorageInterface $tok
return ['id' => $user->getUsername()];
}

return ['id' => (string) $user];
return ['id' => (string)$user];
}));
}

/**
* Setup the client paths.
*
* @param \Bugsnag\Client $client
* @param string|null $strip
* @param string|null $project
* @param string|null $root
* @param string|null $strip
* @param string|null $project
* @param string|null $root
*
* @return void
*/
Expand Down Expand Up @@ -321,4 +332,15 @@ protected function setupPaths(Client $client, $strip, $project, $root)
}
}
}


/**
* @return array|\string[]
*/
public function getExcepts()
{
if (is_array($this->excepts))
return $this->excepts;
return [];
}
}
5 changes: 5 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function getConfigTreeBuilder()
->treatNullLike([])
->defaultValue([])
->end()
->arrayNode('notify_excepts')
->prototype('scalar')->end()
->treatNullLike([])
->defaultValue([])
->end()
->arrayNode('filters')
->prototype('scalar')->end()
->treatNullLike([])
Expand Down
44 changes: 32 additions & 12 deletions EventListener/BugsnagListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bugsnag\BugsnagBundle\EventListener;

use Bugsnag\BugsnagBundle\DependencyInjection\ClientFactory;
use Bugsnag\BugsnagBundle\Request\SymfonyResolver;
use Bugsnag\Client;
use Bugsnag\Report;
Expand Down Expand Up @@ -33,20 +34,22 @@ class BugsnagListener
*/
protected $auto;

protected $clientFactory;

/**
* Create a new bugsnag listener instance.
*
* @param \Bugsnag\Client $client
* @param \Bugsnag\BugsnagBundle\Request\SymfonyResolver $resolver
* @param bool $auto
*
* @return void
* BugsnagListener constructor.
* @param Client $client
* @param SymfonyResolver $resolver
* @param $auto
* @param ClientFactory $clientFactory
*/
public function __construct(Client $client, SymfonyResolver $resolver, $auto)
public function __construct(Client $client, SymfonyResolver $resolver, $auto, ClientFactory $clientFactory)
{

$this->client = $client;
$this->resolver = $resolver;
$this->auto = $auto;
$this->clientFactory = $clientFactory;
}

/**
Expand Down Expand Up @@ -76,13 +79,14 @@ public function onKernelRequest(GetResponseEvent $event)
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{

if (!$this->auto) {
return;
}

$exception = $event->getException();

$this->client->notifyException($exception);
$this->notifyException($exception);
}

/**
Expand All @@ -107,8 +111,24 @@ public function onConsoleException(ConsoleExceptionEvent $event)
],
];

$this->client->notifyException($exception, function (Report $report) use ($meta) {
$report->setMetaData($meta);
});
$this->notifyException($exception, $meta);
}


private function notifyException($exception, $meta = null)
{
$excepts = $this->clientFactory->getExcepts();

if (in_array(get_class($exception), $excepts)) {
return;
}

if (empty($meta)) {
$this->client->notifyException($exception);
} else {
$this->client->notifyException($exception, function (Report $report) use ($meta) {
$report->setMetaData($meta);
});
}
}
}
2 changes: 2 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
- '%kernel.environment%'
- '%bugsnag.notify_release_stages%'
- '%bugsnag.filters%'
- '%bugsnag.notify_excepts%'

bugsnag:
class: '%bugsnag.client%'
Expand All @@ -34,6 +35,7 @@ services:
- '@bugsnag'
- '@bugsnag.resolver'
- '%bugsnag.auto_notify%'
- '@bugsnag.factory'
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 256 }
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException, priority: 128 }
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"name": "bugsnag/bugsnag-symfony",
"description": "Official Bugsnag notifier for Symfony applications.",
"name": "roboticsexpert/bugsnag-symfony",
"description": "roboticsexpert Bugsnag notifier for Symfony applications.",
"keywords": ["bugsnag", "exceptions", "errors", "logging", "tracking", "symfony"],
"homepage": "https://github.com/bugsnag/bugsnag-symfony",
"homepage": "https://github.com/roboticsexpert/bugsnag-symfony",
"type": "symfony-bundle",
"license": "MIT",
"authors": [
{
"name": "Mahdi Youseftabar",
"email": "roboticsexpert@gmail.com"
},
{
"name": "James Smith",
"email": "notifiers@bugsnag.com"
Expand Down