@@ -21,7 +21,7 @@ func TestUnaryServerInterceptor(t *testing.T) {
21
21
for _ , tt := range []struct {
22
22
name string
23
23
ctx context.Context
24
- opts sentrygrpc.UnaryServerInterceptorOptions
24
+ opts [] sentrygrpc.Option
25
25
handler func (
26
26
context.Context ,
27
27
* grpchealth.HealthCheckRequest ,
@@ -32,7 +32,6 @@ func TestUnaryServerInterceptor(t *testing.T) {
32
32
{
33
33
name : "does not report when err is nil" ,
34
34
ctx : context .Background (),
35
- opts : sentrygrpc.UnaryServerInterceptorOptions {},
36
35
handler : func (
37
36
ctx context.Context ,
38
37
_ * grpchealth.HealthCheckRequest ,
@@ -44,7 +43,6 @@ func TestUnaryServerInterceptor(t *testing.T) {
44
43
{
45
44
name : "reports all errors by default" ,
46
45
ctx : context .Background (),
47
- opts : sentrygrpc.UnaryServerInterceptorOptions {},
48
46
handler : func (
49
47
context.Context ,
50
48
* grpchealth.HealthCheckRequest ,
@@ -67,10 +65,12 @@ func TestUnaryServerInterceptor(t *testing.T) {
67
65
{
68
66
name : "reports errors that ReportOn returns true" ,
69
67
ctx : context .Background (),
70
- opts : sentrygrpc.UnaryServerInterceptorOptions {
71
- ReportOn : func (err error ) bool {
72
- return errors .Is (err , grpc .ErrServerStopped )
73
- },
68
+ opts : []sentrygrpc.Option {
69
+ sentrygrpc .WithReportOn (
70
+ func (err error ) bool {
71
+ return errors .Is (err , grpc .ErrServerStopped )
72
+ },
73
+ ),
74
74
},
75
75
handler : func (
76
76
context.Context ,
@@ -94,10 +94,12 @@ func TestUnaryServerInterceptor(t *testing.T) {
94
94
{
95
95
name : "does not report errors that ReportOn returns false" ,
96
96
ctx : context .Background (),
97
- opts : sentrygrpc.UnaryServerInterceptorOptions {
98
- ReportOn : func (err error ) bool {
99
- return false
100
- },
97
+ opts : []sentrygrpc.Option {
98
+ sentrygrpc .WithReportOn (
99
+ func (err error ) bool {
100
+ return false
101
+ },
102
+ ),
101
103
},
102
104
handler : func (
103
105
context.Context ,
@@ -110,7 +112,6 @@ func TestUnaryServerInterceptor(t *testing.T) {
110
112
{
111
113
name : "recovers from panic and returns internal error" ,
112
114
ctx : context .Background (),
113
- opts : sentrygrpc.UnaryServerInterceptorOptions {},
114
115
handler : func (
115
116
context.Context ,
116
117
* grpchealth.HealthCheckRequest ,
@@ -128,7 +129,6 @@ func TestUnaryServerInterceptor(t *testing.T) {
128
129
{
129
130
name : "sets hub on context" ,
130
131
ctx : context .Background (),
131
- opts : sentrygrpc.UnaryServerInterceptorOptions {},
132
132
handler : func (
133
133
ctx context.Context ,
134
134
_ * grpchealth.HealthCheckRequest ,
@@ -165,7 +165,7 @@ func TestUnaryServerInterceptor(t *testing.T) {
165
165
}
166
166
defer lis .Close ()
167
167
168
- opt := grpc .UnaryInterceptor (sentrygrpc .UnaryServerInterceptor (tt .opts ))
168
+ opt := grpc .UnaryInterceptor (sentrygrpc .UnaryServerInterceptor (tt .opts ... ))
169
169
server := grpc .NewServer (opt )
170
170
defer server .Stop ()
171
171
@@ -267,26 +267,28 @@ func TestReportOnCodes(t *testing.T) {
267
267
268
268
t .Run (tt .name , func (t * testing.T ) {
269
269
if w , g := tt .want , sentrygrpc .ReportOnCodes (tt .codes ... )(tt .err ); w != g {
270
- t .Fatalf ("ReportOnCodes: want %t, got %t" , w , g )
270
+ t .Fatalf ("want %t, got %t" , w , g )
271
271
}
272
272
})
273
273
}
274
274
}
275
275
276
276
func ExampleUnaryServerInterceptor () {
277
- opts := sentrygrpc.UnaryServerInterceptorOptions {
277
+ opts := [] sentrygrpc.Option {
278
278
// Reports on OutOfRange or Internal error.
279
- ReportOn : sentrygrpc .ReportOnCodes (
280
- codes .OutOfRange ,
281
- codes .Internal ,
279
+ sentrygrpc .WithReportOn (
280
+ sentrygrpc .ReportOnCodes (
281
+ codes .OutOfRange ,
282
+ codes .Internal ,
283
+ ),
282
284
),
283
285
// Recovers from panic, reports it and returns internal error.
284
- Repanic : false ,
286
+ sentrygrpc . WithRepanic ( false ) ,
285
287
}
286
288
287
289
// This middleware sets *sentry.Hub to context. You can set user to
288
290
// hub's scope in the later interceptor for example.
289
- sentry := sentrygrpc .UnaryServerInterceptor (opts )
291
+ sentry := sentrygrpc .UnaryServerInterceptor (opts ... )
290
292
291
293
server := grpc .NewServer (grpc .UnaryInterceptor (sentry ))
292
294
defer server .Stop ()
0 commit comments