@@ -18,17 +18,35 @@ class HappyIntegration {
18
18
}
19
19
}
20
20
21
- class HappyTransport extends Sentry . Transports . BaseTransport {
22
- sendEvent ( event ) {
21
+ function makeHappyTransport ( options ) {
22
+ function makeRequest ( request ) {
23
23
console . log (
24
- `This is the place where you'd implement your own sending logic. It'd get url: ${ this . url } and an event itself :` ,
25
- event ,
24
+ `This is the place to implement your own sending logic. It'd get url: ${ options . url } and a raw envelope :` ,
25
+ request . body ,
26
26
) ;
27
27
28
- return Promise . resolve ( {
29
- status : 'success' ,
30
- } ) ;
28
+ // this is where your sending logic goes
29
+ const myCustomRequest = {
30
+ body : request . body ,
31
+ method : 'POST' ,
32
+ referrerPolicy : 'origin' ,
33
+ headers : options . headers ,
34
+ ...options . fetchOptions
35
+ } ;
36
+
37
+ // you define how `sendMyCustomRequest` works
38
+ const sendMyCustomRequest = ( r ) => fetch ( options . url , r ) ;
39
+ return sendMyCustomRequest ( myCustomRequest ) . then ( response => ( {
40
+ statusCode : response . status ,
41
+ headers : {
42
+ 'x-sentry-rate-limits' : response . headers . get ( 'X-Sentry-Rate-Limits' ) ,
43
+ 'retry-after' : response . headers . get ( 'Retry-After' ) ,
44
+ } ,
45
+ } ) ) ;
31
46
}
47
+
48
+ // `createTransport` takes care of rate limiting and flushing
49
+ return Sentry . createTransport ( options , makeRequest ) ;
32
50
}
33
51
34
52
Sentry . init ( {
@@ -39,7 +57,7 @@ Sentry.init({
39
57
// An array of strings or regexps that'll be used to ignore specific errors based on their origin url
40
58
denyUrls : [ 'external-lib.js' ] ,
41
59
// An array of strings or regexps that'll be used to allow specific errors based on their origin url
42
- allowUrls : [ 'http://localhost:5000 ' , 'https://browser.sentry-cdn' ] ,
60
+ allowUrls : [ 'http://localhost:3000 ' , 'https://browser.sentry-cdn' ] ,
43
61
// Debug mode with valuable initialization/lifecycle informations.
44
62
debug : true ,
45
63
// Whether SDK should be enabled or not.
@@ -53,7 +71,7 @@ Sentry.init({
53
71
// An environment identifier.
54
72
environment : 'staging' ,
55
73
// Custom event transport that will be used to send things to Sentry
56
- transport : HappyTransport ,
74
+ transport : makeHappyTransport ,
57
75
// Method called for every captured event
58
76
async beforeSend ( event , hint ) {
59
77
// Because beforeSend and beforeBreadcrumb are async, user can fetch some data
0 commit comments