Skip to content

Add option and API to disable Sentry reporting on demand #21

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

Closed
wants to merge 2 commits into from
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ sentry:

The following can be configured via ``app/config/config.yml``:

### enabled

Enable or disable reporting to Sentry. Defaults to true.

### app_path

The base path to your application. Used to trim prefixes and mark frames as part of your application.
Expand Down
3 changes: 3 additions & 0 deletions src/Sentry/SentryBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->booleanNode('enabled')
->defaultTrue()
->end()
->scalarNode('app_path')
->defaultValue('%kernel.root_dir%')
->end()
Expand Down
25 changes: 24 additions & 1 deletion src/Sentry/SentryBundle/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@ class ExceptionListener
/** @var string[] */
private $skipCapture;

/** @var bool */
private $reportingIsEnabled;

/**
* ExceptionListener constructor.
* @param TokenStorageInterface $tokenStorage
* @param AuthorizationCheckerInterface $authorizationChecker
* @param \Raven_Client $client
* @param array $skipCapture
* @param $reportingIsEnabled
*/
public function __construct(
TokenStorageInterface $tokenStorage = null,
AuthorizationCheckerInterface $authorizationChecker = null,
\Raven_Client $client = null,
array $skipCapture
array $skipCapture,
$reportingIsEnabled
) {
$this->reportingIsEnabled = $reportingIsEnabled;

if (!$client) {
$client = new SentrySymfonyClient();
}
Expand All @@ -52,6 +59,14 @@ public function __construct(
$this->skipCapture = $skipCapture;
}

/**
* @param bool $reportingIsEnabled
*/
public function setReportingEnabled($reportingIsEnabled)
{
$this->reportingIsEnabled = $reportingIsEnabled;
}

/**
* @param \Raven_Client $client
*/
Expand Down Expand Up @@ -86,6 +101,10 @@ public function onKernelRequest(GetResponseEvent $event)
*/
public function onKernelException(GetResponseForExceptionEvent $event)
{
if (!$this->reportingIsEnabled) {
return;
}

$exception = $event->getException();

foreach ($this->skipCapture as $className) {
Expand All @@ -102,6 +121,10 @@ public function onKernelException(GetResponseForExceptionEvent $event)
*/
public function onConsoleException(ConsoleExceptionEvent $event)
{
if (!$this->reportingIsEnabled) {
return;
}

$command = $event->getCommand();
$exception = $event->getException();

Expand Down
1 change: 1 addition & 0 deletions src/Sentry/SentryBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ services:
- '@?security.authorization_checker'
- '@sentry.client'
- '%sentry.skip_capture%'
- '%sentry.enabled%'
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
Expand Down