diff --git a/executor/adapter.go b/executor/adapter.go index e7fbc4927e95c..2df31f3be6b7d 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -596,7 +596,8 @@ func (a *ExecStmt) logAudit() { audit := plugin.DeclareAuditManifest(p.Manifest) if audit.OnGeneralEvent != nil { cmd := mysql.Command2Str[byte(atomic.LoadUint32(&a.Ctx.GetSessionVars().CommandValue))] - audit.OnGeneralEvent(context.Background(), sessVars, plugin.Log, cmd) + ctx := context.WithValue(context.Background(), plugin.ExecStartTimeCtxKey, a.StartTime) + audit.OnGeneralEvent(ctx, sessVars, plugin.Log, cmd) } return nil }) diff --git a/plugin/audit.go b/plugin/audit.go index 603b7e0f8982f..f1471562fc657 100644 --- a/plugin/audit.go +++ b/plugin/audit.go @@ -84,3 +84,8 @@ type AuditManifest struct { // OnParseEvent will be called around parse logic. OnParseEvent func(ctx context.Context, sctx *variable.SessionVars, event ParseEvent) error } + +const ( + // ExecStartTimeCtxKey indicates stmt start execution time. + ExecStartTimeCtxKey = "ExecStartTime" +)