diff --git a/src/Database/Statistics.php b/src/Database/Statistics.php index db63eb75..a105dad6 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; } @@ -111,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;", @@ -124,6 +132,7 @@ public function logJPX($reqStartDate, $reqEndDate, $sourceId) { $result = $this->_dbConnection->query($sql); } catch (Exception $e) { + $this->_reportDatabaseError($e); return false; } @@ -155,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); } } @@ -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; }