Explorar o código

Add panic recovery log with distinguishable event_name
- This allows us to more cleanly filter and ship only
this log type for now

Rod Hynes %!s(int64=9) %!d(string=hai) anos
pai
achega
87e4d070ed
Modificáronse 2 ficheiros con 14 adicións e 3 borrados
  1. 3 3
      psiphon/server/api.go
  2. 11 0
      psiphon/server/log.go

+ 3 - 3
psiphon/server/api.go

@@ -22,6 +22,7 @@ package server
 import (
 	"crypto/subtle"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"net"
 	"regexp"
@@ -97,9 +98,8 @@ func dispatchAPIRequestHandler(
 	// terminating in the case of a bug.
 	defer func() {
 		if e := recover(); e != nil {
-			reterr = common.ContextError(
-				fmt.Errorf(
-					"request handler panic: %s: %s", e, debug.Stack()))
+			log.LogPanicRecover(e, string(debug.Stack()))
+			reterr = common.ContextError(errors.New("request handler panic"))
 		}
 	}()
 

+ 11 - 0
psiphon/server/log.go

@@ -98,6 +98,17 @@ func (logger *ContextLogger) LogRawFieldsWithTimestamp(fields LogFields) {
 		customJSONFormatterLogRawFieldsWithTimestamp)
 }
 
+// LogPanicRecover calls LogRawFieldsWithTimestamp with standard fields
+// for logging recovered panics.
+func (logger *ContextLogger) LogPanicRecover(recoverValue interface{}, stack string) {
+	log.LogRawFieldsWithTimestamp(
+		LogFields{
+			"event_name":    "panic",
+			"recover_value": recoverValue,
+			"stack":         stack,
+		})
+}
+
 // NewLogWriter returns an io.PipeWriter that can be used to write
 // to the global logger. Caller must Close() the writer.
 func NewLogWriter() *io.PipeWriter {