mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 02:35:55 +08:00
chore: error log on query error (#7553)
* chore: error log or query error * chore: no error on context cancel
This commit is contained in:
parent
838ef5dcc5
commit
e17f63a50c
@ -2,6 +2,8 @@ package telemetrystorehook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
@ -30,12 +32,21 @@ func (logging) BeforeQuery(ctx context.Context, event *telemetrystore.QueryEvent
|
||||
}
|
||||
|
||||
func (hook *logging) AfterQuery(ctx context.Context, event *telemetrystore.QueryEvent) {
|
||||
hook.logger.Log(
|
||||
ctx,
|
||||
hook.level,
|
||||
"::TELEMETRYSTORE-QUERY::",
|
||||
level := hook.level
|
||||
args := []any{
|
||||
"db.query.text", event.Query,
|
||||
"db.query.args", event.QueryArgs,
|
||||
"db.duration", time.Since(event.StartTime).String(),
|
||||
}
|
||||
if event.Err != nil && !errors.Is(event.Err, sql.ErrNoRows) && !errors.Is(event.Err, context.Canceled) {
|
||||
level = slog.LevelError
|
||||
args = append(args, "db.query.error", event.Err)
|
||||
}
|
||||
|
||||
hook.logger.Log(
|
||||
ctx,
|
||||
level,
|
||||
"::TELEMETRYSTORE-QUERY::",
|
||||
args...,
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user