Skip to content

Commit

Permalink
Fix command input handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stayallive committed Oct 12, 2022
1 parent fd85d9b commit 3650984
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/Sentry/Laravel/EventHandler.php
Expand Up @@ -27,6 +27,9 @@
use Sentry\Breadcrumb;
use Sentry\SentrySdk;
use Sentry\State\Scope;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;

class EventHandler
{
Expand Down Expand Up @@ -568,9 +571,9 @@ protected function commandStartingHandler(CommandStarting $event)
Breadcrumb::TYPE_DEFAULT,
'artisan.command',
'Starting Artisan command: ' . $event->command,
method_exists($event->input, '__toString') ? [
'input' => (string)$event->input,
] : []
[
'input' => $this->extractCommandInput($event->input),
]
));
}
}
Expand All @@ -588,11 +591,10 @@ protected function commandFinishedHandler(CommandFinished $event)
Breadcrumb::TYPE_DEFAULT,
'artisan.command',
'Finished Artisan command: ' . $event->command,
array_merge([
[
'exit' => $event->exitCode,
], method_exists($event->input, '__toString') ? [
'input' => (string)$event->input,
] : [])
'input' => $this->extractCommandInput($event->input),
],
));
}

Expand All @@ -604,6 +606,20 @@ protected function commandFinishedHandler(CommandFinished $event)
Integration::flushEvents();
}

/** @return array|string|null */
private function extractCommandInput(InputInterface $input)
{
$extracted = null;

if ($input instanceof ArgvInput) {
$extracted = (string)$input;
} elseif ($input instanceof ArrayInput) {
$extracted = $input->getArguments();
}

return $extracted;
}

protected function octaneRequestReceivedHandler(Octane\RequestReceived $event): void
{
$this->prepareScopeForOctane();
Expand Down

0 comments on commit 3650984

Please sign in to comment.