Skip to content

Commit c82c075

Browse files
authored
Merge pull request #20 from janwytze/master
Add option to disable capturing the request body
2 parents 4d2322c + 8d43b16 commit c82c075

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

config.go

+12
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,15 @@ func (r *operationNameOverride) Apply(o *options) {
7777
func WithOperationNameOverride(s string) Option {
7878
return &operationNameOverride{OperationNameOverride: s}
7979
}
80+
81+
type captureRequestBodyOption struct {
82+
CaptureRequestBody bool
83+
}
84+
85+
func (c *captureRequestBodyOption) Apply(o *options) {
86+
o.CaptureRequestBody = c.CaptureRequestBody
87+
}
88+
89+
func WithCaptureRequestBody(b bool) Option {
90+
return &captureRequestBodyOption{CaptureRequestBody: b}
91+
}

options.go

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var defaultOptions = &options{
1818
ReportOn: ReportAlways,
1919
Timeout: 1 * time.Second,
2020
OperationNameOverride: "",
21+
CaptureRequestBody: true,
2122
}
2223

2324
type options struct {
@@ -33,6 +34,9 @@ type options struct {
3334
ReportOn func(error) bool
3435

3536
OperationNameOverride string
37+
38+
// CaptureRequestBody configures whether the request body should be sent to Sentry.
39+
CaptureRequestBody bool
3640
}
3741

3842
func ReportAlways(error) bool {

server_interceptors.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
5151
ctx = span.Context()
5252
defer span.Finish()
5353

54-
// TODO: Perhaps makes sense to use SetRequestBody instead?
55-
hub.Scope().SetExtra("requestBody", req)
54+
if o.CaptureRequestBody {
55+
// TODO: Perhaps makes sense to use SetRequestBody instead?
56+
hub.Scope().SetExtra("requestBody", req)
57+
}
5658
defer recoverWithSentry(hub, ctx, o)
5759

5860
resp, err := handler(ctx, req)

0 commit comments

Comments
 (0)