Skip to content

Commit

Permalink
fix: only log slow sql query parameters if trace logging is enabled
Browse files Browse the repository at this point in the history
Signed-off-by: John Mezger <mezger.10@gmail.com>
  • Loading branch information
john.mezger committed Jul 1, 2024
1 parent be5e94c commit 4a4470f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func ObserveSQL(start time.Time, errCode string, sql util.Stripped, args ...inte
duration := time.Since(start)
SQLTime.WithLabelValues(errCode).Observe(duration.Seconds())
if SlowSQLThreshold > 0 && duration >= SlowSQLThreshold {
logrus.Infof("Slow SQL (started: %v) (total time: %v): %s : %v", start, duration, sql, args)
if logrus.GetLevel() == logrus.TraceLevel {
logrus.Tracef("Slow SQL (started: %v) (total time: %v): %s : %v", start, duration, sql, args)
} else {
logrus.Infof("Slow SQL (started: %v) (total time: %v): %s", start, duration, sql)
}
}
}

0 comments on commit 4a4470f

Please sign in to comment.