mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-21 18:01:11 +00:00
feat: add tracing logs after process is complete (#8680)
- Add the written HTTP status after completing the HTTP response. This makes it easier to find that one request that returns a different status code (ref. https://codeberg.org/Codeberg/Community/issues/2049#issue-1972600) - Add the affected amount of rows and last insert ID after the SQL query is done, I have not yet a concrete use-case but this might help with debugging which ID corresponds to some SQL query that someone might want to take a closer look at and if some SQL query affects more than necessary amount of rows. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8680 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
24014c349e
commit
02de040a5e
2 changed files with 14 additions and 1 deletions
|
@ -386,6 +386,15 @@ func (TracingHook) BeforeProcess(c *contexts.ContextHook) (context.Context, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TracingHook) AfterProcess(c *contexts.ContextHook) error {
|
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()
|
c.Ctx.Value(sqlTask{}).(*trace.Task).End()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,11 @@ func ProtocolMiddlewares() (handlers []any) {
|
||||||
defer finished()
|
defer finished()
|
||||||
trace.Log(ctx, "method", req.Method)
|
trace.Log(ctx, "method", req.Method)
|
||||||
trace.Log(ctx, "url", req.RequestURI)
|
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())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue