@@ -138,11 +138,13 @@ func (r *Router) recoverWrap(h http.HandlerFunc) http.HandlerFunc {
138
138
err = sdk .ErrUnknownError
139
139
}
140
140
141
- log . Error ( context . TODO (), "[PANIC_RECOVERY] Panic occurred on %s:%s, recover %s" , req .Method , req . URL . String (), err )
141
+ ctx := req .Context ( )
142
142
143
143
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 )
146
148
147
149
//Checking if there are two much panics in two minutes
148
150
//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 {
165
167
log .Error (req .Context (), "[PANIC_RECOVERY] RESTART NEEDED" )
166
168
}
167
169
168
- service .WriteError (req . Context () , w , req , err )
170
+ service .WriteError (ctx , w , req , err )
169
171
}
170
172
}()
171
173
h .ServeHTTP (w , req )
0 commit comments