Skip to content

Commit

Permalink
fix(db): Increase log level for very slow transactions
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>

[skip ci]
  • Loading branch information
ChristophWurst authored and AndyScherzinger committed Sep 4, 2024
1 parent d76b763 commit 3a1c4fd
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,20 @@ public function commit() {
$this->transactionBacktrace = null;
$this->transactionActiveSince = null;
if ($timeTook > 1) {
$this->logger->debug('Transaction took ' . $timeTook . 's', ['exception' => new \Exception('Transaction took ' . $timeTook . 's')]);
$logLevel = match (true) {
$timeTook > 20 * 60 => ILogger::ERROR,
$timeTook > 5 * 60 => ILogger::WARN,
$timeTook > 10 => ILogger::INFO,
default => ILogger::DEBUG,
};
$this->logger->log(
$logLevel,
'Transaction took ' . $timeTook . 's',
[
'exception' => new \Exception('Transaction took ' . $timeTook . 's'),
'timeSpent' => $timeTook,
]
);
}
}
return $result;
Expand All @@ -750,7 +763,20 @@ public function rollBack() {
$this->transactionBacktrace = null;
$this->transactionActiveSince = null;
if ($timeTook > 1) {
$this->logger->debug('Transaction rollback took longer than 1s: ' . $timeTook, ['exception' => new \Exception('Long running transaction rollback')]);
$logLevel = match (true) {
$timeTook > 20 * 60 => ILogger::ERROR,
$timeTook > 5 * 60 => ILogger::WARN,
$timeTook > 10 => ILogger::INFO,
default => ILogger::DEBUG,
};
$this->logger->log(
$logLevel,
'Transaction rollback took longer than 1s: ' . $timeTook,
[
'exception' => new \Exception('Long running transaction rollback'),
'timeSpent' => $timeTook,
]
);
}
}
return $result;
Expand Down

0 comments on commit 3a1c4fd

Please sign in to comment.