27
27
use Sentry \Breadcrumb ;
28
28
use Sentry \SentrySdk ;
29
29
use Sentry \State \Scope ;
30
+ use Symfony \Component \Console \Input \ArgvInput ;
31
+ use Symfony \Component \Console \Input \InputInterface ;
30
32
31
33
class EventHandler
32
34
{
@@ -568,9 +570,9 @@ protected function commandStartingHandler(CommandStarting $event)
568
570
Breadcrumb::TYPE_DEFAULT ,
569
571
'artisan.command ' ,
570
572
'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
+ ]
574
576
));
575
577
}
576
578
}
@@ -588,20 +590,35 @@ protected function commandFinishedHandler(CommandFinished $event)
588
590
Breadcrumb::TYPE_DEFAULT ,
589
591
'artisan.command ' ,
590
592
'Finished Artisan command: ' . $ event ->command ,
591
- array_merge ( [
593
+ [
592
594
'exit ' => $ event ->exitCode ,
593
- ], method_exists ($ event ->input , '__toString ' ) ? [
594
- 'input ' => (string )$ event ->input ,
595
- ] : [])
595
+ 'input ' => $ this ->extractConsoleCommandInput ($ event ->input ),
596
+ ]
596
597
));
597
598
}
598
599
600
+ // Flush any and all events that were possibly generated by the command
601
+ Integration::flushEvents ();
602
+
599
603
Integration::configureScope (static function (Scope $ scope ): void {
600
- $ scope ->setTag ('command ' , ' ' );
604
+ $ scope ->removeTag ('command ' );
601
605
});
606
+ }
602
607
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 ;
605
622
}
606
623
607
624
protected function octaneRequestReceivedHandler (Octane \RequestReceived $ event ): void
0 commit comments