1- import { Event } from '@sentry/types' ;
1+ import { Event , TransactionSamplingMethod } from '@sentry/types' ;
22
33import { API } from '../../src/api' ;
44import { eventToSentryRequest } from '../../src/request' ;
@@ -16,25 +16,41 @@ describe('eventToSentryRequest', () => {
1616 user : { id : '1121' , username : 'CharlieDog' , ip_address : '11.21.20.12' } ,
1717 } ;
1818
19- it ( 'adds sampling information to transaction item header' , ( ) => {
20- event . tags = { __sentry_samplingMethod : 'client_rate' , __sentry_sampleRate : '0.1121' , dog : 'Charlie' } ;
21-
22- const result = eventToSentryRequest ( event as Event , api ) ;
23-
24- const [ envelopeHeaderString , itemHeaderString , eventString ] = result . body . split ( '\n' ) ;
25-
26- const envelope = {
27- envelopeHeader : JSON . parse ( envelopeHeaderString ) ,
28- itemHeader : JSON . parse ( itemHeaderString ) ,
29- event : JSON . parse ( eventString ) ,
30- } ;
31-
32- // the right stuff is added to the item header
33- expect ( envelope . itemHeader ) . toEqual ( { type : 'transaction' , sample_rates : [ { id : 'client_rate' , rate : '0.1121' } ] } ) ;
34-
35- // show that it pops the right tags and leaves the rest alone
36- expect ( '__sentry_samplingMethod' in envelope . event . tags ) . toBe ( false ) ;
37- expect ( '__sentry_sampleRate' in envelope . event . tags ) . toBe ( false ) ;
38- expect ( 'dog' in envelope . event . tags ) . toBe ( true ) ;
19+ [
20+ { method : TransactionSamplingMethod . Rate , rate : '0.1121' , dog : 'Charlie' } ,
21+ { method : TransactionSamplingMethod . Sampler , rate : '0.1231' , dog : 'Maisey' } ,
22+ { method : TransactionSamplingMethod . Inheritance , dog : 'Cory' } ,
23+ { method : TransactionSamplingMethod . Explicit , dog : 'Bodhi' } ,
24+
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
27+ { dog : 'Lucy' } ,
28+ ] . forEach ( ( { method, rate, dog } ) => {
29+ it ( `adds transaction sampling information to item header - ${ method } , ${ rate } , ${ dog } ` , ( ) => {
30+ // TODO kmclb - once tag types are loosened, don't need to cast to string here
31+ event . tags = { __sentry_samplingMethod : String ( method ) , __sentry_sampleRate : String ( rate ) , dog } ;
32+
33+ const result = eventToSentryRequest ( event as Event , api ) ;
34+
35+ const [ envelopeHeaderString , itemHeaderString , eventString ] = result . body . split ( '\n' ) ;
36+
37+ const envelope = {
38+ envelopeHeader : JSON . parse ( envelopeHeaderString ) ,
39+ itemHeader : JSON . parse ( itemHeaderString ) ,
40+ event : JSON . parse ( eventString ) ,
41+ } ;
42+
43+ // the right stuff is added to the item header
44+ expect ( envelope . itemHeader ) . toEqual ( {
45+ type : 'transaction' ,
46+ // TODO kmclb - once tag types are loosened, don't need to cast to string here
47+ sample_rates : [ { id : String ( method ) , rate : String ( rate ) } ] ,
48+ } ) ;
49+
50+ // show that it pops the right tags and leaves the rest alone
51+ expect ( '__sentry_samplingMethod' in envelope . event . tags ) . toBe ( false ) ;
52+ expect ( '__sentry_sampleRate' in envelope . event . tags ) . toBe ( false ) ;
53+ expect ( 'dog' in envelope . event . tags ) . toBe ( true ) ;
54+ } ) ;
3955 } ) ;
4056} ) ;
0 commit comments