Skip to content

Commit

Permalink
limit sql length to avoid breaking the json (#326)
Browse files Browse the repository at this point in the history
* limit sql length to avoid breaking the json

* Added as config+env var

* Update pulse.php

* Update SlowQueries.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
kima92 and taylorotwell authored Mar 11, 2024
1 parent 5285c67 commit 6fc88b3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/pulse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_query_length' => env('PULSE_SLOW_QUERIES_MAX_QUERY_LENGTH', null),
'ignore' => [
'/(["`])pulse_[\w]+?\1/', // Pulse tables...
'/(["`])telescope_[\w]+?\1/', // Telescope tables...
Expand Down
4 changes: 4 additions & 0 deletions src/Recorders/SlowQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function record(QueryExecuted $event): void
return;
}

if ($maxQueryLength = $this->config->get('pulse.recorders.'.self::class.'.max_query_length')) {
$sql = Str::limit($sql, $maxQueryLength);
}

$this->pulse->record(
type: 'slow_query',
key: json_encode([$sql, $location], flags: JSON_THROW_ON_ERROR),
Expand Down

0 comments on commit 6fc88b3

Please sign in to comment.