From 7f84f08c17ae6cdec73cbafe42cfb309bc5335da Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Wed, 8 Nov 2023 14:18:28 -0800 Subject: [PATCH] CLI-1208: Stop AMA-related bugsnag errors (#1628) --- src/Helpers/TelemetryHelper.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Helpers/TelemetryHelper.php b/src/Helpers/TelemetryHelper.php index 880d78c7c..8ff4c93a6 100644 --- a/src/Helpers/TelemetryHelper.php +++ b/src/Helpers/TelemetryHelper.php @@ -11,6 +11,7 @@ use AcquiaCloudApi\Endpoints\Account; use Bugsnag\Client; use Bugsnag\Handler; +use Bugsnag\Report; use League\OAuth2\Client\Provider\Exception\IdentityProviderException; use loophp\phposinfo\OsInfo; use Symfony\Component\Filesystem\Path; @@ -45,15 +46,19 @@ public function initializeBugsnag(): void { $bugsnag = Client::make($this->bugSnagKey); $bugsnag->setAppVersion($this->application->getVersion()); $bugsnag->setProjectRoot(Path::join(__DIR__, '..')); - $bugsnag->registerCallback(function (mixed $report): void { + $bugsnag->registerCallback(function (Report $report): bool { + // Exclude reports from app:from, which bootstraps Drupal. + // We aren't responsible for Drupal application errors. + if (str_starts_with($report->getContext(), 'GET')) { + return FALSE; + } + // Set user info. $userId = $this->getUserId(); if (isset($userId)) { $report->setUser([ 'id' => $userId, ]); } - }); - $bugsnag->registerCallback(function (mixed $report): void { $context = $report->getContext(); // Strip working directory and binary from context. if (str_contains($context, 'acli ')) { @@ -64,6 +69,7 @@ public function initializeBugsnag(): void { $context = substr($context, 0, strpos($context, "--password") + 10) . 'REDACTED'; } $report->setContext($context); + return TRUE; }); Handler::register($bugsnag); }