diff options
Diffstat (limited to 'internal/db')
| -rw-r--r-- | internal/db/bundb/trace.go | 14 | 
1 files changed, 12 insertions, 2 deletions
| diff --git a/internal/db/bundb/trace.go b/internal/db/bundb/trace.go index e62e8c01f..82b50c058 100644 --- a/internal/db/bundb/trace.go +++ b/internal/db/bundb/trace.go @@ -20,6 +20,7 @@ package bundb  import (  	"context" +	"database/sql"  	"time"  	"github.com/sirupsen/logrus" @@ -46,8 +47,17 @@ func (q *debugQueryHook) BeforeQuery(ctx context.Context, event *bun.QueryEvent)  func (q *debugQueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) {  	dur := time.Since(event.StartTime).Round(time.Microsecond)  	l := q.log.WithFields(logrus.Fields{ -		"queryTime": dur, +		"duration":  dur,  		"operation": event.Operation(),  	}) -	l.Trace(event.Query) + +	if event.Err != nil && event.Err != sql.ErrNoRows { +		// if there's an error the it'll be handled in the application logic, +		// but we can still debug log it here alongside the query +		l = l.WithField("query", event.Query) +		l.Debug(event.Err) +		return +	} + +	l.Tracef("[%s] %s", dur, event.Operation())  } | 
