From f3bf0d3868db7fa1a3a02dcbb22083656585d113 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Briseno Date: Tue, 9 Jun 2026 15:08:23 -0400 Subject: [PATCH 1/3] Report Statistics SQL errors to Sentry --- src/Database/Statistics.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Database/Statistics.php b/src/Database/Statistics.php index db63eb75..4fb17529 100644 --- a/src/Database/Statistics.php +++ b/src/Database/Statistics.php @@ -17,11 +17,20 @@ use DeviceDetector\ClientHints; use DeviceDetector\DeviceDetector; +use Helioviewer\Api\Sentry\Sentry; class Database_Statistics { private $_dbConnection; + /** + * Report a database failure to Sentry tagged as "Database Error". + */ + private function _reportDatabaseError(\Throwable $e): void { + Sentry::setTag('error_type', 'Database Error'); + Sentry::capture($e); + } + /** * Constructor * @@ -94,6 +103,7 @@ public function log($action) { $result = $this->_dbConnection->query($sql); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -124,6 +134,7 @@ public function logJPX($reqStartDate, $reqEndDate, $sourceId) { $result = $this->_dbConnection->query($sql); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -204,7 +215,7 @@ public function saveStatisticsFromRedis($redis){ } } catch (Exception $e) { - + $this->_reportDatabaseError($e); } } @@ -253,7 +264,7 @@ public function saveRateLimitExceededFromRedis($redis){ } } catch (Exception $e) { - + $this->_reportDatabaseError($e); } } @@ -481,6 +492,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu $result = $this->_dbConnection->query($sql); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -526,6 +538,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu $result = $this->_dbConnection->query($sql); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -552,6 +565,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu $result = $this->_dbConnection->query($sql); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -600,6 +614,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu $resultScreenshots = $this->_dbConnection->query($sqlScreenshots); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -651,6 +666,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu $resultScreenshots = $this->_dbConnection->query($sqlScreenshots); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -718,6 +734,7 @@ public function getUsageStatistics($resolution, $dateStart = null, $dateEnd = nu $result = $this->_dbConnection->query($sql); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } From 754323155829b34761c832e62d848a5f36fc4d88 Mon Sep 17 00:00:00 2001 From: Daniel Garcia Briseno Date: Tue, 9 Jun 2026 15:31:15 -0400 Subject: [PATCH 2/3] Don't set NULL on timestamp, let DB fill it in --- src/Database/Statistics.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Database/Statistics.php b/src/Database/Statistics.php index 4fb17529..a95d7bca 100644 --- a/src/Database/Statistics.php +++ b/src/Database/Statistics.php @@ -121,8 +121,6 @@ public function logJPX($reqStartDate, $reqEndDate, $sourceId) { $sql = sprintf( "INSERT INTO movies_jpx " . "SET " - . "id " . " = NULL, " - . "timestamp " . " = NULL, " . "reqStartDate " . " = '%s', " . "reqEndDate " . " = '%s', " . "sourceId " . " = %d;", @@ -131,10 +129,13 @@ public function logJPX($reqStartDate, $reqEndDate, $sourceId) { $this->_dbConnection->link->real_escape_string($sourceId) ); try { + echo $sql; $result = $this->_dbConnection->query($sql); } catch (Exception $e) { $this->_reportDatabaseError($e); + var_dump($e); + echo "DEAD"; return false; } From 1dffc04a1d5b86d082fec2f49b84f509b5636ace Mon Sep 17 00:00:00 2001 From: Daniel Garcia Briseno Date: Thu, 11 Jun 2026 12:32:05 -0400 Subject: [PATCH 3/3] Add logging to Statistics.php for redis failure --- src/Database/Statistics.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Database/Statistics.php b/src/Database/Statistics.php index a95d7bca..a105dad6 100644 --- a/src/Database/Statistics.php +++ b/src/Database/Statistics.php @@ -129,13 +129,10 @@ public function logJPX($reqStartDate, $reqEndDate, $sourceId) { $this->_dbConnection->link->real_escape_string($sourceId) ); try { - echo $sql; $result = $this->_dbConnection->query($sql); } catch (Exception $e) { $this->_reportDatabaseError($e); - var_dump($e); - echo "DEAD"; return false; } @@ -167,6 +164,8 @@ public function logRedis($action, $redis = null){ $redis->incr($key); }catch(Exception $e){ //continue gracefully if redis statistics logging fails + Sentry::setTag('error_type', 'Redis Error'); + Sentry::capture($e); } }