@@ -6,6 +6,7 @@ package server
6
6
7
7
import (
8
8
"context"
9
+ "net/http"
9
10
10
11
"github.com/gitpod-io/gitpod/common-go/log"
11
12
@@ -15,28 +16,25 @@ import (
15
16
16
17
func NewLogInterceptor (entry * logrus.Entry ) connect.UnaryInterceptorFunc {
17
18
interceptor := func (next connect.UnaryFunc ) connect.UnaryFunc {
18
- return connect . UnaryFunc ( func (ctx context.Context , req connect.AnyRequest ) (connect.AnyResponse , error ) {
19
+ return func (ctx context.Context , req connect.AnyRequest ) (connect.AnyResponse , error ) {
19
20
ctx = log .ToContext (ctx , entry .WithContext (ctx ))
20
21
21
22
log .AddFields (ctx , logrus.Fields {
22
23
"requestProtocol" : "connect" ,
23
24
"requestProcedure" : req .Spec ().Procedure ,
24
25
"address" : req .Peer ().Addr ,
25
26
"requestStreamType" : streamType (req .Spec ().StreamType ),
26
- "requestHeaders" : req .Header (),
27
+ "requestHeaders" : filterHeaders ( req .Header () ),
27
28
})
28
29
log .Extract (ctx ).Debugf ("Handling request for %s" , req .Spec ().Procedure )
29
30
30
31
resp , err := next (ctx , req )
31
32
32
- // Retrieve the logger from the context again, in case it's been updated.
33
33
code := codeOf (err )
34
34
log .AddFields (ctx , logrus.Fields {"responseCode" : code })
35
35
36
36
if err != nil {
37
37
log .AddFields (ctx , logrus.Fields {logrus .ErrorKey : err })
38
- } else {
39
- log .AddFields (ctx , logrus.Fields {"responseBody" : resp .Any ()})
40
38
}
41
39
42
40
if req .Spec ().IsClient {
@@ -45,14 +43,24 @@ func NewLogInterceptor(entry *logrus.Entry) connect.UnaryInterceptorFunc {
45
43
} else {
46
44
log .Extract (ctx ).Infof ("Received response for %s with code %s" , req .Spec ().Procedure , code )
47
45
}
48
- log .Extract (ctx ).Errorf ("Received response for %s with code %s" , req .Spec ().Procedure , code )
49
46
} else {
50
- log .Extract (ctx ).Warnf ("Completed handling of request for %s with code %s" , req .Spec ().Procedure , code )
47
+ if err != nil {
48
+ log .Extract (ctx ).Warnf ("Completed handling of request for %s with code %s" , req .Spec ().Procedure , code )
49
+ } else {
50
+ log .Extract (ctx ).Debugf ("Completed handling of request for %s with code %s" , req .Spec ().Procedure , code )
51
+ }
51
52
}
52
53
53
54
return resp , err
54
- })
55
+ }
55
56
}
56
57
57
- return connect .UnaryInterceptorFunc (interceptor )
58
+ return interceptor
59
+ }
60
+
61
+ func filterHeaders (headers http.Header ) http.Header {
62
+ cloned := headers .Clone ()
63
+ cloned .Del ("Authorization" )
64
+ cloned .Del ("Cookie" )
65
+ return cloned
58
66
}
0 commit comments