Skip to content

Commit

Permalink
Merge pull request #20 from janwytze/master
Browse files Browse the repository at this point in the history
Add option to disable capturing the request body
  • Loading branch information
johnbellone authored Apr 19, 2024
2 parents 4d2322c + 8d43b16 commit c82c075
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@ func (r *operationNameOverride) Apply(o *options) {
func WithOperationNameOverride(s string) Option {
return &operationNameOverride{OperationNameOverride: s}
}

type captureRequestBodyOption struct {
CaptureRequestBody bool
}

func (c *captureRequestBodyOption) Apply(o *options) {
o.CaptureRequestBody = c.CaptureRequestBody
}

func WithCaptureRequestBody(b bool) Option {
return &captureRequestBodyOption{CaptureRequestBody: b}
}
4 changes: 4 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var defaultOptions = &options{
ReportOn: ReportAlways,
Timeout: 1 * time.Second,
OperationNameOverride: "",
CaptureRequestBody: true,
}

type options struct {
Expand All @@ -33,6 +34,9 @@ type options struct {
ReportOn func(error) bool

OperationNameOverride string

// CaptureRequestBody configures whether the request body should be sent to Sentry.
CaptureRequestBody bool
}

func ReportAlways(error) bool {
Expand Down
6 changes: 4 additions & 2 deletions server_interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor {
ctx = span.Context()
defer span.Finish()

// TODO: Perhaps makes sense to use SetRequestBody instead?
hub.Scope().SetExtra("requestBody", req)
if o.CaptureRequestBody {
// TODO: Perhaps makes sense to use SetRequestBody instead?
hub.Scope().SetExtra("requestBody", req)
}
defer recoverWithSentry(hub, ctx, o)

resp, err := handler(ctx, req)
Expand Down

0 comments on commit c82c075

Please sign in to comment.