@@ -16,14 +16,74 @@ describe('eventToSentryRequest', () => {
1616 user : { id : '1121' , username : 'CharlieDog' , ip_address : '11.21.20.12' } ,
1717 } ;
1818
19+ it ( 'injects correct data for error/message events' , ( ) => {
20+ const event = {
21+ event_id : '1231201211212012' ,
22+ exception : { values : [ { type : 'PuppyProblemsError' , value : 'Charlie ate the flip-flops :-(' } ] } ,
23+ user : { id : '1121' , username : 'CharlieDog' , ip_address : '11.21.20.12' } ,
24+ } ;
25+
26+ const result = eventToSentryRequest ( event , api ) ;
27+ expect ( result . type ) . toEqual ( 'event' ) ;
28+ expect ( result . url ) . toEqual (
29+ 'https://squirrelchasers.ingest.sentry.io/api/12312012/store/?sentry_key=dogsarebadatkeepingsecrets&sentry_version=7' ,
30+ ) ;
31+ expect ( result . body ) . toEqual ( JSON . stringify ( event ) ) ;
32+ } ) ;
33+
34+ it ( 'injects correct data for transaction events' , ( ) => {
35+ const eventId = '1231201211212012' ;
36+ const traceId = '0908201304152013' ;
37+ const event = {
38+ contexts : { trace : { trace_id : traceId , span_id : '12261980' , op : 'pageload' } } ,
39+ environment : 'dogpark' ,
40+ event_id : eventId ,
41+ release : 'off.leash.park' ,
42+ spans : [ ] ,
43+ transaction : '/dogs/are/great/' ,
44+ type : 'transaction' ,
45+ user : { id : '1121' , username : 'CharlieDog' , ip_address : '11.21.20.12' } ,
46+ } ;
47+
48+ const result = eventToSentryRequest ( event as Event , api ) ;
49+
50+ const [ envelopeHeaderString , itemHeaderString , eventString ] = result . body . split ( '\n' ) ;
51+
52+ const envelope = {
53+ envelopeHeader : JSON . parse ( envelopeHeaderString ) ,
54+ itemHeader : JSON . parse ( itemHeaderString ) ,
55+ event : JSON . parse ( eventString ) ,
56+ } ;
57+
58+ expect ( result . type ) . toEqual ( 'transaction' ) ;
59+ expect ( result . url ) . toEqual (
60+ 'https://squirrelchasers.ingest.sentry.io/api/12312012/envelope/?sentry_key=dogsarebadatkeepingsecrets&sentry_version=7' ,
61+ ) ;
62+ expect ( envelope . envelopeHeader ) . toEqual ( {
63+ event_id : eventId ,
64+ sent_at : expect . any ( String ) ,
65+ trace : {
66+ environment : 'dogpark' ,
67+ public_key : 'dogsarebadatkeepingsecrets' ,
68+ release : 'off.leash.park' ,
69+ trace_id : traceId ,
70+ } ,
71+ } ) ;
72+ expect ( envelope . itemHeader ) . toEqual ( {
73+ type : 'transaction' ,
74+ sample_rates : expect . any ( Array ) ,
75+ } ) ;
76+ expect ( envelope . event ) . toEqual ( event ) ;
77+ } ) ;
78+
1979 [
2080 { method : TransactionSamplingMethod . Rate , rate : '0.1121' , dog : 'Charlie' } ,
2181 { method : TransactionSamplingMethod . Sampler , rate : '0.1231' , dog : 'Maisey' } ,
2282 { method : TransactionSamplingMethod . Inheritance , dog : 'Cory' } ,
2383 { method : TransactionSamplingMethod . Explicit , dog : 'Bodhi' } ,
2484
25- // this shouldn't ever happen (at least the method should always be included in tags ), but good to know that things
26- // won't blow up if it does
85+ // this shouldn't ever happen (tags should always include at least the sampling method ), but good to know that
86+ // things won't blow up if it does happen
2787 { dog : 'Lucy' } ,
2888 ] . forEach ( ( { method, rate, dog } ) => {
2989 it ( `adds transaction sampling information to item header - ${ method } , ${ rate } , ${ dog } ` , ( ) => {
0 commit comments