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

[BUGFIX] do not report everything to sentry, let the user configure t… #9

Merged
merged 4 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions Classes/Service/Sentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Sentry\SentrySdk;
use Sentry\State\Scope;
use Throwable;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\SingletonInterface;
Expand All @@ -28,6 +29,7 @@ class Sentry implements SingletonInterface
protected bool $queue;
protected bool $withGitReleases;
protected ScopeConfig $scopeConfig;
protected int $errorsToReport;

/**
* @throws \TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException
Expand All @@ -40,6 +42,11 @@ public function __construct(ScopeConfig $config, ExtensionConfiguration $configu
$this->dsn = getenv('SENTRY_DSN') ?: $_ENV['SENTRY_DSN'] ?: $configuration->get('sentry', 'sentry_dsn') ?: '';
$this->queue = (bool)filter_var(getenv('SENTRY_QUEUE') ?: $_ENV['SENTRY_QUEUE'] ?: $configuration->get('sentry', 'sentry_queue') ?: 0, FILTER_VALIDATE_INT);
$disabled = filter_var($env['DISABLE_SENTRY'] ?? $configuration->get('sentry', 'force_disable_sentry'), FILTER_VALIDATE_INT);
try {
$this->errorsToReport = filter_var($env['SENTRY_ERRORS_TO_REPORT'] ?? $configuration->get('sentry', 'sentry_errors_to_report') ?: ($GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'] ?? E_ALL), FILTER_VALIDATE_INT);
} catch (ExtensionConfigurationPathDoesNotExistException $e) {
$this->errorsToReport = $GLOBALS['TYPO3_CONF_VARS']['SYS']['exceptionalErrors'] ?? E_ALL;
}
Kanti marked this conversation as resolved.
Show resolved Hide resolved

$this->enabled = $disabled === 0 && $this->dsn;

Expand All @@ -59,6 +66,7 @@ protected function setup(): void
'environment' => preg_replace('/[\/\s]/', '', Environment::getContext()),
'dsn' => $this->dsn,
'attach_stacktrace' => true,
'error_types' => $this->errorsToReport,
];

if ($this->withGitReleases) {
Expand Down Expand Up @@ -93,8 +101,7 @@ protected function populateScope(Scope $scope): void
*/
public static function getInstance(): self
{
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
return $objectManager->get(static::class);
return GeneralUtility::makeInstance(ObjectManager::class)->get(static::class);
}

public function getClient(): ?ClientInterface
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `SENTRY_DSN=https://dsn-to-your@sentry.io/instance`
- `DISABLE_SENTRY` (optional) Disable Sentry by setting this to 1
- `SENTRY_QUEUE` (optional) Enable queue system by setting this to 1
- `SENTRY_ERRORS_TO_REPORT` (optional) The Errors to Report as number, e.g. 4096 for E_REVOERABLE_ERROR
- Add the following line to your `AdditionalConfiguration.php`
- `(new \Pluswerk\Sentry\Bootstrap())->initializeHandler();`
- If you enabled SENTRY_QUEUE
Expand Down
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ sentry_dsn =

# cat=sentry; type=boolean; label=Queue active
sentry_queue =

# cat=sentry; type=integer; label=The Errors to Report as number, e.g. 4096 for E_REVOERABLE_ERROR
sentry_errors_to_report =