Skip to content

Commit

Permalink
fix(api): set the stacktrace as a field (#5803)
Browse files Browse the repository at this point in the history
Signed-off-by: francois  samin <[email protected]>
  • Loading branch information
fsamin authored Apr 30, 2021
1 parent 10eebf1 commit 06b65d2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions engine/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ func (r *Router) recoverWrap(h http.HandlerFunc) http.HandlerFunc {
err = sdk.ErrUnknownError
}

log.Error(context.TODO(), "[PANIC_RECOVERY] Panic occurred on %s:%s, recover %s", req.Method, req.URL.String(), err)
ctx := req.Context()

trace := make([]byte, 4096)
count := runtime.Stack(trace, true)
log.Error(req.Context(), "[PANIC_RECOVERY] Stacktrace of %d bytes\n%s\n", count, trace)
_ = runtime.Stack(trace, true)

ctx = context.WithValue(ctx, cdslog.Stacktrace, string(trace))
log.Error(ctx, "[PANIC] Panic occurred on %s:%s, recover %s", req.Method, req.URL.String(), err)

//Checking if there are two much panics in two minutes
//If last panic was more than 2 minutes ago, reinit the panic counter
Expand All @@ -165,7 +167,7 @@ func (r *Router) recoverWrap(h http.HandlerFunc) http.HandlerFunc {
log.Error(req.Context(), "[PANIC_RECOVERY] RESTART NEEDED")
}

service.WriteError(req.Context(), w, req, err)
service.WriteError(ctx, w, req, err)
}
}()
h.ServeHTTP(w, req)
Expand Down

0 comments on commit 06b65d2

Please sign in to comment.