-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the hub injected in the constructor of the listeners rather than …
…retrieving it from the SDK singleton
- Loading branch information
Showing
20 changed files
with
1,100 additions
and
851 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
includes: | ||
- phpstan-baseline.neon | ||
|
||
parameters: | ||
level: 7 | ||
paths: | ||
- src/ | ||
- test/ | ||
ignoreErrors: | ||
- '/Symfony\\Component\\HttpKernel\\Event\\(GetResponse|FilterController)Event not found.$/' | ||
includes: | ||
- phpstan-baseline.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Sentry\SentryBundle\EventListener; | ||
|
||
use Sentry\State\HubInterface; | ||
use Sentry\State\Scope; | ||
use Symfony\Component\Console\Event\ConsoleErrorEvent; | ||
|
||
/** | ||
* This listener handles all errors thrown while running a console command and | ||
* logs them to Sentry. | ||
*/ | ||
final class ConsoleCommandListener | ||
{ | ||
/** | ||
* @var HubInterface The current hub | ||
*/ | ||
private $hub; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param HubInterface $hub The current hub | ||
*/ | ||
public function __construct(HubInterface $hub) | ||
{ | ||
$this->hub = $hub; | ||
} | ||
|
||
/** | ||
* Handles an error that happened while running a console command. | ||
* | ||
* @param ConsoleErrorEvent $event The event | ||
*/ | ||
public function handleConsoleErrorEvent(ConsoleErrorEvent $event): void | ||
{ | ||
$this->hub->withScope(function (Scope $scope) use ($event): void { | ||
$command = $event->getCommand(); | ||
|
||
if (null !== $command && null !== $command->getName()) { | ||
$scope->setTag('console.command', $command->getName()); | ||
} | ||
|
||
$scope->setTag('console.command.exit_code', (string) $event->getExitCode()); | ||
|
||
$this->hub->captureException($event->getError()); | ||
}); | ||
} | ||
} |
Oops, something went wrong.