@@ -16,18 +16,20 @@ import (
16
16
"github.com/gin-gonic/gin"
17
17
"github.com/google/go-cmp/cmp"
18
18
"github.com/google/go-cmp/cmp/cmpopts"
19
+ "github.com/stretchr/testify/require"
19
20
)
20
21
21
22
func TestIntegration (t * testing.T ) {
22
23
largePayload := strings .Repeat ("Large" , 3 * 1024 ) // 15 KB
23
24
24
25
tests := []struct {
25
- RequestPath string
26
- RoutePath string
27
- Method string
28
- WantStatus int
29
- Body string
30
- Handler gin.HandlerFunc
26
+ RequestPath string
27
+ RoutePath string
28
+ Method string
29
+ WantStatus int
30
+ Body string
31
+ Handler gin.HandlerFunc
32
+ Instrumenter string
31
33
32
34
WantEvent * sentry.Event
33
35
WantTransaction * sentry.Event
@@ -284,25 +286,20 @@ func TestIntegration(t *testing.T) {
284
286
},
285
287
WantEvent : nil ,
286
288
},
289
+ {
290
+ RequestPath : "/404/1" ,
291
+ RoutePath : "/otel" ,
292
+ Method : "GET" ,
293
+ Instrumenter : "otel" ,
294
+ WantStatus : 404 ,
295
+ Handler : nil ,
296
+ WantTransaction : nil ,
297
+ WantEvent : nil ,
298
+ },
287
299
}
288
300
289
301
eventsCh := make (chan * sentry.Event , len (tests ))
290
302
transactionsCh := make (chan * sentry.Event , len (tests ))
291
- err := sentry .Init (sentry.ClientOptions {
292
- EnableTracing : true ,
293
- TracesSampleRate : 1.0 ,
294
- BeforeSend : func (event * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
295
- eventsCh <- event
296
- return event
297
- },
298
- BeforeSendTransaction : func (tx * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
299
- transactionsCh <- tx
300
- return tx
301
- },
302
- })
303
- if err != nil {
304
- t .Fatal (err )
305
- }
306
303
307
304
router := gin .New ()
308
305
router .Use (sentrygin .New (sentrygin.Options {}))
@@ -321,17 +318,34 @@ func TestIntegration(t *testing.T) {
321
318
var wanttrans []* sentry.Event
322
319
var wantCodes []sentry.SpanStatus
323
320
for _ , tt := range tests {
321
+ err := sentry .Init (sentry.ClientOptions {
322
+ EnableTracing : true ,
323
+ TracesSampleRate : 1.0 ,
324
+ Instrumenter : tt .Instrumenter ,
325
+ BeforeSend : func (event * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
326
+ eventsCh <- event
327
+ return event
328
+ },
329
+ BeforeSendTransaction : func (tx * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
330
+ transactionsCh <- tx
331
+ return tx
332
+ },
333
+ })
334
+ require .NoError (t , err )
335
+
324
336
if tt .WantEvent != nil && tt .WantEvent .Request != nil {
325
337
wantRequest := tt .WantEvent .Request
326
338
wantRequest .URL = srv .URL + wantRequest .URL
327
339
wantRequest .Headers ["Host" ] = srv .Listener .Addr ().String ()
328
340
want = append (want , tt .WantEvent )
329
341
}
330
- wantTransaction := tt .WantTransaction .Request
331
- wantTransaction .URL = srv .URL + wantTransaction .URL
332
- wantTransaction .Headers ["Host" ] = srv .Listener .Addr ().String ()
333
- wanttrans = append (wanttrans , tt .WantTransaction )
334
- wantCodes = append (wantCodes , sentry .HTTPtoSpanStatus (tt .WantStatus ))
342
+ if tt .WantTransaction != nil {
343
+ wantTransaction := tt .WantTransaction .Request
344
+ wantTransaction .URL = srv .URL + wantTransaction .URL
345
+ wantTransaction .Headers ["Host" ] = srv .Listener .Addr ().String ()
346
+ wanttrans = append (wanttrans , tt .WantTransaction )
347
+ wantCodes = append (wantCodes , sentry .HTTPtoSpanStatus (tt .WantStatus ))
348
+ }
335
349
336
350
req , err := http .NewRequest (tt .Method , srv .URL + tt .RequestPath , strings .NewReader (tt .Body ))
337
351
if err != nil {
0 commit comments