From 18711c92a2df0e565435b5805fc88a1ca6d3aeb6 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 29 Jan 2024 13:16:09 +0100 Subject: [PATCH 1/3] Show more output by default --- src/Sentry/Laravel/Console/TestCommand.php | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Sentry/Laravel/Console/TestCommand.php b/src/Sentry/Laravel/Console/TestCommand.php index 7a929808..86393007 100644 --- a/src/Sentry/Laravel/Console/TestCommand.php +++ b/src/Sentry/Laravel/Console/TestCommand.php @@ -33,11 +33,11 @@ class TestCommand extends Command protected $description = 'Generate a test event and send it to Sentry'; /** - * Buffer of log messages generated by the Sentry SDK. + * Buffer of error messages generated by the Sentry SDK. * * @var array */ - private $logMessages = []; + private $errorMessages = []; /** * Execute the console command. @@ -110,10 +110,15 @@ public function __construct(TestCommand $command) public function log($level, $message, array $context = []): void { - $this->command->info("SDK({$level}): {$message}", OutputInterface::VERBOSITY_VERBOSE); + // Only show debug, info and notice messages in verbose mode + $verbosity = in_array($level, ['debug', 'info', 'notice'], true) + ? OutputInterface::VERBOSITY_VERBOSE + : OutputInterface::VERBOSITY_NORMAL; - if ($level === 'error') { - $this->command->logMessageFromSDK($message); + $this->command->info("SDK({$level}): {$message}", $verbosity); + + if (in_array($level, ['error', 'critical'], true)) { + $this->command->logErrorMessageFromSDK($message); } } }); @@ -137,7 +142,7 @@ public function log($level, $message, array $context = []): void $this->info("Test event sent with ID: {$eventId}"); if ($this->option('transaction')) { - $this->clearLogMessagesFromSDK(); + $this->clearErrorMessagesFromSDK(); $transactionContext = new TransactionContext(); $transactionContext->setSampled(true); @@ -191,26 +196,21 @@ protected function generateTestException($command, $arg): Exception } } - public function logMessageFromSDK(string $message): void + public function logErrorMessageFromSDK(string $message): void { - $this->logMessages[] = $message; + $this->errorMessages[] = $message; } - private function clearLogMessagesFromSDK(): void + private function clearErrorMessagesFromSDK(): void { - $this->logMessages = []; + $this->errorMessages = []; } private function printDebugTips(): void { - $emittedSDKErrors = false; $probablySSLError = false; - foreach ($this->logMessages as $logMessage) { - $emittedSDKErrors = true; - - $this->error("SDK: {$logMessage}"); - + foreach ($this->errorMessages as $logMessage) { if (Str::contains($logMessage, ['SSL certificate problem', 'certificate has expired'])) { $probablySSLError = true; } @@ -219,7 +219,7 @@ private function printDebugTips(): void if ($probablySSLError) { $this->warn('The problem might be related to the Let\'s Encrypt root certificate that expired and your machine not having an up-to-date enough OpenSSL version or still having the expired root in your certificate authority store.'); $this->warn('For more information you can check out this forum post from Let\'s Encrypt that contains helpful links on how to resolve this for your environment: https://community.letsencrypt.org/t/production-chain-changes/150739/4'); - } elseif ($emittedSDKErrors) { + } elseif (count($this->errorMessages) > 0) { $this->error('Please check the error message from the SDK above for further hints about what went wrong.'); } else { $this->error('Please check if your DSN is set properly in your `.env` as `SENTRY_LARAVEL_DSN` or in your config file `config/sentry.php`.'); From 0edcfb660433995556205eed084431bf52d9e48b Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 29 Jan 2024 13:16:20 +0100 Subject: [PATCH 2/3] Ensure the cURL extension is enabled --- src/Sentry/Laravel/Console/TestCommand.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Sentry/Laravel/Console/TestCommand.php b/src/Sentry/Laravel/Console/TestCommand.php index 86393007..e67da1ee 100644 --- a/src/Sentry/Laravel/Console/TestCommand.php +++ b/src/Sentry/Laravel/Console/TestCommand.php @@ -46,6 +46,12 @@ class TestCommand extends Command */ public function handle(): int { + if (!\extension_loaded('curl')) { + $this->error('The cURL PHP extension must be enabled.'); + + return 1; + } + // Maximize error reporting $old_error_reporting = error_reporting(E_ALL | E_STRICT); From f3de53385ace60bf5a9348fac73f1f8a4ceb8380 Mon Sep 17 00:00:00 2001 From: Alex Bouma Date: Mon, 29 Jan 2024 13:48:21 +0100 Subject: [PATCH 3/3] Update src/Sentry/Laravel/Console/TestCommand.php Co-authored-by: Michi Hoffmann --- src/Sentry/Laravel/Console/TestCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry/Laravel/Console/TestCommand.php b/src/Sentry/Laravel/Console/TestCommand.php index e67da1ee..e6695f30 100644 --- a/src/Sentry/Laravel/Console/TestCommand.php +++ b/src/Sentry/Laravel/Console/TestCommand.php @@ -47,7 +47,7 @@ class TestCommand extends Command public function handle(): int { if (!\extension_loaded('curl')) { - $this->error('The cURL PHP extension must be enabled.'); + $this->error('You need to enable the PHP cURL extension (ext-curl).'); return 1; }