Skip to content

Commit 06b65d2

Browse files
authored
fix(api): set the stacktrace as a field (#5803)
Signed-off-by: francois samin <[email protected]>
1 parent 10eebf1 commit 06b65d2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

engine/api/router.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ func (r *Router) recoverWrap(h http.HandlerFunc) http.HandlerFunc {
138138
err = sdk.ErrUnknownError
139139
}
140140

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

143143
trace := make([]byte, 4096)
144-
count := runtime.Stack(trace, true)
145-
log.Error(req.Context(), "[PANIC_RECOVERY] Stacktrace of %d bytes\n%s\n", count, trace)
144+
_ = runtime.Stack(trace, true)
145+
146+
ctx = context.WithValue(ctx, cdslog.Stacktrace, string(trace))
147+
log.Error(ctx, "[PANIC] Panic occurred on %s:%s, recover %s", req.Method, req.URL.String(), err)
146148

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

168-
service.WriteError(req.Context(), w, req, err)
170+
service.WriteError(ctx, w, req, err)
169171
}
170172
}()
171173
h.ServeHTTP(w, req)

0 commit comments

Comments
 (0)