From 1fcc2d6e42b5a1afe7bbbb4e0922335789bc4cd3 Mon Sep 17 00:00:00 2001 From: kima92 <40360720+kima92@users.noreply.github.com> Date: Wed, 6 Mar 2024 12:56:42 +0000 Subject: [PATCH 1/4] limit sql length to avoid breaking the json --- src/Recorders/SlowQueries.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Recorders/SlowQueries.php b/src/Recorders/SlowQueries.php index a1e74ef0..de056788 100644 --- a/src/Recorders/SlowQueries.php +++ b/src/Recorders/SlowQueries.php @@ -57,7 +57,7 @@ public function record(QueryExecuted $event): void $this->pulse->record( type: 'slow_query', - key: json_encode([$sql, $location], flags: JSON_THROW_ON_ERROR), + key: json_encode([Str::limit($sql, 65000), $location], flags: JSON_THROW_ON_ERROR), value: $duration, timestamp: (int) (($timestampMs - $duration) / 1000), )->max()->count(); From cc92b3f0c1d245616a105b71def469d6810a9fbe Mon Sep 17 00:00:00 2001 From: kima92 <40360720+kima92@users.noreply.github.com> Date: Sun, 10 Mar 2024 16:17:30 +0000 Subject: [PATCH 2/4] Added as config+env var --- config/pulse.php | 1 + src/Recorders/SlowQueries.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/pulse.php b/config/pulse.php index 68ee12b4..4d67ec98 100644 --- a/config/pulse.php +++ b/config/pulse.php @@ -196,6 +196,7 @@ 'threshold' => env('PULSE_SLOW_QUERIES_THRESHOLD', 1000), 'location' => env('PULSE_SLOW_QUERIES_LOCATION', true), 'highlighting' => env('PULSE_SLOW_QUERIES_HIGHLIGHTING', true), + 'max_sql_length' => env('PULSE_SLOW_QUERIES_MAX_SQL_LENGTH', null), 'ignore' => [ '/(["`])pulse_[\w]+?\1/', // Pulse tables... '/(["`])telescope_[\w]+?\1/', // Telescope tables... diff --git a/src/Recorders/SlowQueries.php b/src/Recorders/SlowQueries.php index de056788..01fd0c46 100644 --- a/src/Recorders/SlowQueries.php +++ b/src/Recorders/SlowQueries.php @@ -55,9 +55,13 @@ public function record(QueryExecuted $event): void return; } + if ($maxSqlLength = $this->config->get('pulse.recorders.'.self::class.'.max_sql_length')) { + $sql = Str::limit($sql, $maxSqlLength); + } + $this->pulse->record( type: 'slow_query', - key: json_encode([Str::limit($sql, 65000), $location], flags: JSON_THROW_ON_ERROR), + key: json_encode([$sql, $location], flags: JSON_THROW_ON_ERROR), value: $duration, timestamp: (int) (($timestampMs - $duration) / 1000), )->max()->count(); From df5e1ffaddd085818f6d5cd01a679c7b05317f2b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 11 Mar 2024 08:13:37 -0500 Subject: [PATCH 3/4] Update pulse.php --- config/pulse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/pulse.php b/config/pulse.php index 4d67ec98..2eb95ccc 100644 --- a/config/pulse.php +++ b/config/pulse.php @@ -196,7 +196,7 @@ 'threshold' => env('PULSE_SLOW_QUERIES_THRESHOLD', 1000), 'location' => env('PULSE_SLOW_QUERIES_LOCATION', true), 'highlighting' => env('PULSE_SLOW_QUERIES_HIGHLIGHTING', true), - 'max_sql_length' => env('PULSE_SLOW_QUERIES_MAX_SQL_LENGTH', null), + 'max_query_length' => env('PULSE_SLOW_QUERIES_MAX_QUERY_LENGTH', null), 'ignore' => [ '/(["`])pulse_[\w]+?\1/', // Pulse tables... '/(["`])telescope_[\w]+?\1/', // Telescope tables... From 388d43f421aafdc93e7a579aa269a52f1f6187b1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 11 Mar 2024 08:14:01 -0500 Subject: [PATCH 4/4] Update SlowQueries.php --- src/Recorders/SlowQueries.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Recorders/SlowQueries.php b/src/Recorders/SlowQueries.php index 01fd0c46..6f0b5791 100644 --- a/src/Recorders/SlowQueries.php +++ b/src/Recorders/SlowQueries.php @@ -55,8 +55,8 @@ public function record(QueryExecuted $event): void return; } - if ($maxSqlLength = $this->config->get('pulse.recorders.'.self::class.'.max_sql_length')) { - $sql = Str::limit($sql, $maxSqlLength); + if ($maxQueryLength = $this->config->get('pulse.recorders.'.self::class.'.max_query_length')) { + $sql = Str::limit($sql, $maxQueryLength); } $this->pulse->record(