2727use Sentry \Breadcrumb ;
2828use Sentry \SentrySdk ;
2929use Sentry \State \Scope ;
30+ use Symfony \Component \Console \Input \ArgvInput ;
31+ use Symfony \Component \Console \Input \InputInterface ;
3032
3133class EventHandler
3234{
@@ -568,9 +570,9 @@ protected function commandStartingHandler(CommandStarting $event)
568570 Breadcrumb::TYPE_DEFAULT ,
569571 'artisan.command ' ,
570572 'Starting Artisan command: ' . $ event ->command ,
571- method_exists ( $ event -> input , ' __toString ' ) ? [
572- 'input ' => ( string ) $ event ->input ,
573- ] : []
573+ [
574+ 'input ' => $ this -> extractConsoleCommandInput ( $ event ->input ) ,
575+ ]
574576 ));
575577 }
576578 }
@@ -588,20 +590,35 @@ protected function commandFinishedHandler(CommandFinished $event)
588590 Breadcrumb::TYPE_DEFAULT ,
589591 'artisan.command ' ,
590592 'Finished Artisan command: ' . $ event ->command ,
591- array_merge ( [
593+ [
592594 'exit ' => $ event ->exitCode ,
593- ], method_exists ($ event ->input , '__toString ' ) ? [
594- 'input ' => (string )$ event ->input ,
595- ] : [])
595+ 'input ' => $ this ->extractConsoleCommandInput ($ event ->input ),
596+ ]
596597 ));
597598 }
598599
600+ // Flush any and all events that were possibly generated by the command
601+ Integration::flushEvents ();
602+
599603 Integration::configureScope (static function (Scope $ scope ): void {
600- $ scope ->setTag ('command ' , ' ' );
604+ $ scope ->removeTag ('command ' );
601605 });
606+ }
602607
603- // Flush any and all events that were possibly generated by the command
604- Integration::flushEvents ();
608+ /**
609+ * Extract the command input arguments if possible.
610+ *
611+ * @param \Symfony\Component\Console\Input\InputInterface|null $input
612+ *
613+ * @return string|null
614+ */
615+ private function extractConsoleCommandInput (?InputInterface $ input ): ?string
616+ {
617+ if ($ input instanceof ArgvInput) {
618+ return (string )$ input ;
619+ }
620+
621+ return null ;
605622 }
606623
607624 protected function octaneRequestReceivedHandler (Octane \RequestReceived $ event ): void
0 commit comments