@@ -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
@@ -291,26 +293,20 @@ func TestIntegration(t *testing.T) {
291
293
},
292
294
WantEvent : nil ,
293
295
},
296
+ {
297
+ RequestPath : "/404/1" ,
298
+ RoutePath : "/otel" ,
299
+ Method : "GET" ,
300
+ Instrumenter : "otel" ,
301
+ WantStatus : 404 ,
302
+ Handler : nil ,
303
+ WantTransaction : nil ,
304
+ WantEvent : nil ,
305
+ },
294
306
}
295
307
296
308
eventsCh := make (chan * sentry.Event , len (tests ))
297
309
transactionsCh := make (chan * sentry.Event , len (tests ))
298
- err := sentry .Init (sentry.ClientOptions {
299
- EnableTracing : true ,
300
- TracesSampleRate : 1.0 ,
301
- BeforeSend : func (event * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
302
- eventsCh <- event
303
- return event
304
- },
305
- BeforeSendTransaction : func (tx * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
306
- fmt .Println ("BeforeSendTransaction" )
307
- transactionsCh <- tx
308
- return tx
309
- },
310
- })
311
- if err != nil {
312
- t .Fatal (err )
313
- }
314
310
315
311
router := gin .New ()
316
312
router .Use (sentrygin .New (sentrygin.Options {}))
@@ -329,17 +325,34 @@ func TestIntegration(t *testing.T) {
329
325
var wanttrans []* sentry.Event
330
326
var wantCodes []sentry.SpanStatus
331
327
for _ , tt := range tests {
328
+ err := sentry .Init (sentry.ClientOptions {
329
+ EnableTracing : true ,
330
+ TracesSampleRate : 1.0 ,
331
+ Instrumenter : tt .Instrumenter ,
332
+ BeforeSend : func (event * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
333
+ eventsCh <- event
334
+ return event
335
+ },
336
+ BeforeSendTransaction : func (tx * sentry.Event , hint * sentry.EventHint ) * sentry.Event {
337
+ transactionsCh <- tx
338
+ return tx
339
+ },
340
+ })
341
+ require .NoError (t , err )
342
+
332
343
if tt .WantEvent != nil && tt .WantEvent .Request != nil {
333
344
wantRequest := tt .WantEvent .Request
334
345
wantRequest .URL = srv .URL + wantRequest .URL
335
346
wantRequest .Headers ["Host" ] = srv .Listener .Addr ().String ()
336
347
want = append (want , tt .WantEvent )
337
348
}
338
- wantTransaction := tt .WantTransaction .Request
339
- wantTransaction .URL = srv .URL + wantTransaction .URL
340
- wantTransaction .Headers ["Host" ] = srv .Listener .Addr ().String ()
341
- wanttrans = append (wanttrans , tt .WantTransaction )
342
- wantCodes = append (wantCodes , sentry .HTTPtoSpanStatus (tt .WantStatus ))
349
+ if tt .WantTransaction != nil {
350
+ wantTransaction := tt .WantTransaction .Request
351
+ wantTransaction .URL = srv .URL + wantTransaction .URL
352
+ wantTransaction .Headers ["Host" ] = srv .Listener .Addr ().String ()
353
+ wanttrans = append (wanttrans , tt .WantTransaction )
354
+ wantCodes = append (wantCodes , sentry .HTTPtoSpanStatus (tt .WantStatus ))
355
+ }
343
356
344
357
req , err := http .NewRequest (tt .Method , srv .URL + tt .RequestPath , strings .NewReader (tt .Body ))
345
358
if err != nil {
0 commit comments