diff --git a/src/Collectors/CommandCollector.php b/src/Collectors/CommandCollector.php index 7e98b54..6a75d1b 100644 --- a/src/Collectors/CommandCollector.php +++ b/src/Collectors/CommandCollector.php @@ -9,7 +9,6 @@ use Illuminate\Console\Events\CommandStarting; use Illuminate\Support\Facades\Log; use Nipwaayoni\Events\Transaction; -use Throwable; /** * Collects info about ran commands. @@ -75,7 +74,7 @@ protected function send($event): void $this->agent->send(); } catch (ClientException $exception) { Log::error($exception, ['api_response' => (string) $exception->getResponse()->getBody()]); - } catch (Throwable $t) { + } catch (\Throwable $t) { Log::error($t->getMessage()); } } diff --git a/src/Collectors/DBQueryCollector.php b/src/Collectors/DBQueryCollector.php index cd4cf02..997f65d 100644 --- a/src/Collectors/DBQueryCollector.php +++ b/src/Collectors/DBQueryCollector.php @@ -3,7 +3,6 @@ namespace AG\ElasticApmLaravel\Collectors; use AG\ElasticApmLaravel\Contracts\DataCollector; -use Exception; use Illuminate\Database\Events\QueryExecuted; use Jasny\DB\MySQL\QuerySplitter; @@ -73,7 +72,7 @@ private function getQueryName(string $sql): string } return $fallback; - } catch (Exception $e) { + } catch (\Exception $e) { return $fallback; } } diff --git a/src/Collectors/JobCollector.php b/src/Collectors/JobCollector.php index 869adca..d990699 100644 --- a/src/Collectors/JobCollector.php +++ b/src/Collectors/JobCollector.php @@ -11,7 +11,6 @@ use Illuminate\Queue\Jobs\SyncJob; use Illuminate\Support\Facades\Log; use Nipwaayoni\Events\Transaction; -use Throwable; /** * Collects info about the job process. @@ -114,7 +113,7 @@ protected function send(Job $job): void } } catch (ClientException $exception) { Log::error($exception, ['api_response' => (string) $exception->getResponse()->getBody()]); - } catch (Throwable $t) { + } catch (\Throwable $t) { Log::error($t->getMessage()); } } diff --git a/src/Collectors/ScheduledTaskCollector.php b/src/Collectors/ScheduledTaskCollector.php index ca10af5..37b3fe5 100644 --- a/src/Collectors/ScheduledTaskCollector.php +++ b/src/Collectors/ScheduledTaskCollector.php @@ -7,10 +7,10 @@ use Illuminate\Console\Events\ScheduledTaskFinished; use Illuminate\Console\Events\ScheduledTaskSkipped; use Illuminate\Console\Events\ScheduledTaskStarting; +use Illuminate\Console\Scheduling\CallbackEvent; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Log; use Nipwaayoni\Events\Transaction; -use Throwable; /** * Collects info about scheduled tasks. @@ -79,7 +79,7 @@ protected function send($event): void $this->agent->send(); } catch (ClientException $exception) { Log::error($exception, ['api_response' => (string) $exception->getResponse()->getBody()]); - } catch (Throwable $t) { + } catch (\Throwable $t) { Log::error($t->getMessage()); } } @@ -91,7 +91,9 @@ protected function send($event): void */ protected function getTransactionName($event): string { - $transaction_name = $event->task->command; + $transaction_name = $event->task instanceof CallbackEvent + ? $event->task->getSummaryForDisplay() + : $event->task->command; return $this->shouldIgnoreTransaction($transaction_name) ? '' : $transaction_name; } diff --git a/src/Middleware/RecordTransaction.php b/src/Middleware/RecordTransaction.php index b10c0e7..b8b6590 100644 --- a/src/Middleware/RecordTransaction.php +++ b/src/Middleware/RecordTransaction.php @@ -4,14 +4,12 @@ use AG\ElasticApmLaravel\Agent; use AG\ElasticApmLaravel\Collectors\RequestStartTime; -use Closure; use Illuminate\Config\Repository as Config; use Illuminate\Http\Request; use Illuminate\Routing\Route; use Illuminate\Support\Facades\Log; use Nipwaayoni\Events\Transaction; use Symfony\Component\HttpFoundation\Response; -use Throwable; /** * This middleware will record a transaction from the moment the request hits the server, until the response is sent to the client. @@ -42,7 +40,7 @@ public function __construct(Agent $agent, Config $config, RequestStartTime $star * * @return mixed */ - public function handle(Request $request, Closure $next) + public function handle(Request $request, \Closure $next) { $transaction_name = $this->getTransactionName($request); @@ -99,7 +97,7 @@ public function terminate(Request $request): void // Stop the transaction and measure the time $this->agent->stopTransaction($transaction_name); $this->agent->collectEvents($transaction_name); - } catch (Throwable $t) { + } catch (\Throwable $t) { Log::error($t->getMessage()); } } diff --git a/src/Services/ApmCollectorService.php b/src/Services/ApmCollectorService.php index b2ab1f2..c286c79 100644 --- a/src/Services/ApmCollectorService.php +++ b/src/Services/ApmCollectorService.php @@ -9,7 +9,6 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Foundation\Application; use Nipwaayoni\Events\Transaction; -use Throwable; class ApmCollectorService { @@ -83,7 +82,7 @@ public function addCollector(string $collector_class): void ); } - public function captureThrowable(Throwable $thrown, array $context = [], ?Transaction $parent = null) + public function captureThrowable(\Throwable $thrown, array $context = [], ?Transaction $parent = null) { if ($this->is_agent_disabled) { return;