Skip to content

Commit 6ccdf48

Browse files
authored
Log template execution start and end, this would help in tracing any faulty template executions that are leading to memory leaks (#2034)
1 parent c00a5d6 commit 6ccdf48

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

common/templates/context.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,25 @@ func (c *Context) executeParsed() (string, error) {
406406
var buf bytes.Buffer
407407
w := LimitWriter(&buf, 25000)
408408

409-
// started := time.Now()
409+
started := time.Now()
410+
logger.WithFields(logrus.Fields{
411+
"guild_id": c.GS.ID,
412+
"cc_id": c.Data["CCID"],
413+
"executed_from": c.ExecutedFrom,
414+
}).Info("Template execution started")
410415
err := parsed.Execute(w, c.Data)
411416

412-
// dur := time.Since(started)
417+
defer func() {
418+
dur := time.Since(started)
419+
logger.WithFields(logrus.Fields{
420+
"guild_id": c.GS.ID,
421+
"executed_from": c.ExecutedFrom,
422+
"cc_id": c.Data["CCID"],
423+
"success": err == nil,
424+
"duration": dur,
425+
}).Info("Template execution finished")
426+
}()
427+
413428
if c.FixedOutput != "" {
414429
return c.FixedOutput, nil
415430
}

0 commit comments

Comments
 (0)