diff --git a/models/db/engine.go b/models/db/engine.go index 76025f7d67..42b9150696 100755 --- a/models/db/engine.go +++ b/models/db/engine.go @@ -386,6 +386,15 @@ func (TracingHook) BeforeProcess(c *contexts.ContextHook) (context.Context, erro } func (TracingHook) AfterProcess(c *contexts.ContextHook) error { + if c.Result != nil { + if rowsAffected, err := c.Result.RowsAffected(); err == nil { + trace.Logf(c.Ctx, "rows affected", "%d", rowsAffected) + } + if lastID, err := c.Result.LastInsertId(); err == nil { + trace.Logf(c.Ctx, "last insert id", "%d", lastID) + } + } + c.Ctx.Value(sqlTask{}).(*trace.Task).End() return nil } diff --git a/routers/common/middleware.go b/routers/common/middleware.go index d44f046a1e..7bc4890a43 100644 --- a/routers/common/middleware.go +++ b/routers/common/middleware.go @@ -46,7 +46,11 @@ func ProtocolMiddlewares() (handlers []any) { defer finished() trace.Log(ctx, "method", req.Method) trace.Log(ctx, "url", req.RequestURI) - next.ServeHTTP(context.WrapResponseWriter(resp), req.WithContext(cache.WithCacheContext(ctx))) + + respWriter := context.WrapResponseWriter(resp) + next.ServeHTTP(respWriter, req.WithContext(cache.WithCacheContext(ctx))) + + trace.Logf(ctx, "status", "%d", respWriter.WrittenStatus()) }) })