Skip to content

Commit

Permalink
Merge pull request #58 from tstollin/add-stack-trace-to-single
Browse files Browse the repository at this point in the history
add stack trace to panic recovery logging in single.go
  • Loading branch information
Roshick authored Dec 6, 2024
2 parents 8ff27cb + 8e44574 commit 7287ec0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/periodictask/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"golang.org/x/net/context"
)

var StackTraceLogField = "stack-trace"

type Coordinator interface {
locker.Locker

Expand Down
6 changes: 5 additions & 1 deletion pkg/periodictask/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package periodictask
import (
"errors"
"fmt"
"runtime/debug"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -80,7 +81,10 @@ func (r *PeriodicSingleTaskRunner) start(ctx context.Context) {
defer r.terminate()
defer func() {
if err, ok := recover().(error); ok {
aulogging.Logger.Ctx(ctx).Error().WithErr(err).Printf("periodic-task runner '%s' exited due to panic: %+v", r.taskKey, errors.New(fmt.Sprintf("%v", err)))
aulogging.Logger.Ctx(ctx).Error().
WithErr(err).
With(StackTraceLogField, string(debug.Stack())).
Printf("periodic-task runner '%s' exited due to panic: %+v", r.taskKey, errors.New(fmt.Sprintf("%v", err)))
}
}()
r.performTask(ctx)
Expand Down

0 comments on commit 7287ec0

Please sign in to comment.