Skip to content

Commit

Permalink
CLI-1208: Stop AMA-related bugsnag errors (#1628)
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored Nov 8, 2023
1 parent b3904a4 commit 7f84f08
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Helpers/TelemetryHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ')) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 7f84f08

Please sign in to comment.