From 4ecb1c9eb1b77bfbbb1e5d31be74d72acf3356d9 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Fri, 24 Oct 2025 23:59:23 -0400 Subject: [PATCH 1/7] added support for pushing manual logs --- src/Laritor.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Laritor.php b/src/Laritor.php index 3e3173b..4b0b0e6 100644 --- a/src/Laritor.php +++ b/src/Laritor.php @@ -2,6 +2,8 @@ namespace BinaryBuilds\LaritorClient; +use BinaryBuilds\LaritorClient\Recorders\LogRecorder; +use Carbon\Carbon; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Http; @@ -147,6 +149,17 @@ public function addEvents($name, $events) return $this; } + public function addCustomLog(string $type, string $level, string $message, array $context = [], Carbon $written_at = null) + { + $this->events[LogRecorder::$eventType][] = [ + 'level' => $level, + 'message' => $message, + 'log_context' => $context, + 'occurred_at' => $written_at ? $written_at->format('Y-m-d H:i:s') : now()->format('Y-m-d H:i:s'), + 'context' => $type + ]; + } + public function removeScheduler() { unset($this->events[SchedulerRecorder::$eventType]); @@ -309,19 +322,6 @@ public function shouldSendEvents() } catch (\Throwable $exception) {} - $hasOccurrence = false; - - foreach ($this->events as $type => $event) { - if (in_array($type, ['requests', 'commands', 'scheduler', 'scheduled_tasks', 'jobs','server_stats'])) { - $hasOccurrence = true; - break; - } - } - - if (! $hasOccurrence) { - return false; - } - if (app()->runningInConsole() || ! $this->isRateLimiterEnabled() ) { return true; } From 7c97e71395709871466db1df5e23998f715edf51 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Sat, 25 Oct 2025 00:00:33 -0400 Subject: [PATCH 2/7] bump version --- src/Laritor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Laritor.php b/src/Laritor.php index 4b0b0e6..91c6aed 100644 --- a/src/Laritor.php +++ b/src/Laritor.php @@ -13,7 +13,7 @@ class Laritor { - public const VERSION = '2.3.9'; + public const VERSION = '2.3.10'; /** * @var array From 5f7527332d326d08e9690b8a7efddb5385691a99 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Sat, 25 Oct 2025 00:22:04 -0400 Subject: [PATCH 3/7] fix tests --- src/Laritor.php | 2 +- tests/TestCase.php | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Laritor.php b/src/Laritor.php index 91c6aed..e169e3d 100644 --- a/src/Laritor.php +++ b/src/Laritor.php @@ -149,7 +149,7 @@ public function addEvents($name, $events) return $this; } - public function addCustomLog(string $type, string $level, string $message, array $context = [], Carbon $written_at = null) + public function addCustomLog(string $type, string $level, string $message, array $context = [], ?Carbon $written_at = null) { $this->events[LogRecorder::$eventType][] = [ 'level' => $level, diff --git a/tests/TestCase.php b/tests/TestCase.php index 4325fc3..23519e1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -128,12 +128,17 @@ public function toMail($notifiable) { }); $app['router']->get('/laritor-failed-job', function () { - dispatch(function (){ - /** - * @phpstan-ignore-next-line - */ - return $invalid; - }); + try{ + dispatch(function (){ + /** + * @phpstan-ignore-next-line + */ + return $invalid; + }); + } catch (\Throwable $e) { + return response('NOT OK', 500); + } + return response('OK', 200); }); } From a028c77d36e2a230e11b549d7d9f814703582c47 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Sat, 25 Oct 2025 00:23:05 -0400 Subject: [PATCH 4/7] fix tests --- src/Laritor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Laritor.php b/src/Laritor.php index e169e3d..9864661 100644 --- a/src/Laritor.php +++ b/src/Laritor.php @@ -313,6 +313,10 @@ public function sync($data) */ public function shouldSendEvents() { + if (empty($this->events)) { + return false; + } + try { $timeout = trim(file_get_contents(storage_path('laritor-timeout.txt'))); From ddf799623134580ba99d90217c617821ed4f9895 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Sat, 25 Oct 2025 00:27:30 -0400 Subject: [PATCH 5/7] fix tests --- tests/JobTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/JobTest.php b/tests/JobTest.php index da810f8..d79e8e2 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -29,6 +29,9 @@ public function test_it_records_failed_jobs(): void $this->assertFileExists($file); $data = json_decode(file_get_contents($file), true); + + var_dump($data); + $this->assertIsArray($data, 'Payload is not valid JSON'); $this->assertArrayHasKey('events', $data); $this->assertArrayHasKey(QueuedJobRecorder::$eventType, $data['events']); From 6ee699aabb0b425dc51f33bce031e96839eaa991 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Sat, 25 Oct 2025 00:30:58 -0400 Subject: [PATCH 6/7] fix tests --- src/Override/TestOverride.php | 5 +++++ tests/JobTest.php | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Override/TestOverride.php b/src/Override/TestOverride.php index 5ed6d84..490ab3b 100644 --- a/src/Override/TestOverride.php +++ b/src/Override/TestOverride.php @@ -19,4 +19,9 @@ public function recordRequest($request): bool return true; } + + public function recordException($exception): bool + { + return !request()->is('laritor-failed-job'); + } } \ No newline at end of file diff --git a/tests/JobTest.php b/tests/JobTest.php index d79e8e2..76e974b 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -30,8 +30,6 @@ public function test_it_records_failed_jobs(): void $data = json_decode(file_get_contents($file), true); - var_dump($data); - $this->assertIsArray($data, 'Payload is not valid JSON'); $this->assertArrayHasKey('events', $data); $this->assertArrayHasKey(QueuedJobRecorder::$eventType, $data['events']); From cac4dfa9f06b7ee6cdea36295b95be382c997f12 Mon Sep 17 00:00:00 2001 From: Srinath Reddy Dudi Date: Sat, 25 Oct 2025 00:32:06 -0400 Subject: [PATCH 7/7] fix tests --- tests/JobTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/JobTest.php b/tests/JobTest.php index 76e974b..84b45f2 100644 --- a/tests/JobTest.php +++ b/tests/JobTest.php @@ -34,7 +34,5 @@ public function test_it_records_failed_jobs(): void $this->assertArrayHasKey('events', $data); $this->assertArrayHasKey(QueuedJobRecorder::$eventType, $data['events']); $this->assertNotEmpty( $data['events'][QueuedJobRecorder::$eventType]); - $this->assertArrayHasKey(ExceptionRecorder::$eventType, $data['events']); - $this->assertNotEmpty( $data['events'][ExceptionRecorder::$eventType]); } }