@@ -978,6 +978,38 @@ describe('BaseClient', () => {
978978 expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/dogs/are/great' ) ;
979979 } ) ;
980980
981+ test ( 'calls `beforeSendSpan` and uses original spans without any changes' , ( ) => {
982+ expect . assertions ( 2 ) ;
983+
984+ const beforeSendSpan = jest . fn ( span => span ) ;
985+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendSpan } ) ;
986+ const client = new TestClient ( options ) ;
987+
988+ const transaction : Event = {
989+ transaction : '/cats/are/great' ,
990+ type : 'transaction' ,
991+ spans : [
992+ {
993+ description : 'first span' ,
994+ span_id : '9e15bf99fbe4bc80' ,
995+ start_timestamp : 1591603196.637835 ,
996+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
997+ } ,
998+ {
999+ description : 'second span' ,
1000+ span_id : 'aa554c1f506b0783' ,
1001+ start_timestamp : 1591603196.637835 ,
1002+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1003+ } ,
1004+ ] ,
1005+ } ;
1006+ client . captureEvent ( transaction ) ;
1007+
1008+ expect ( beforeSendSpan ) . toHaveBeenCalledTimes ( 2 ) ;
1009+ const capturedEvent = TestClient . instance ! . event ! ;
1010+ expect ( capturedEvent . spans ) . toEqual ( transaction . spans ) ;
1011+ } ) ;
1012+
9811013 test ( 'calls `beforeSend` and uses the modified event' , ( ) => {
9821014 expect . assertions ( 2 ) ;
9831015
@@ -1010,6 +1042,45 @@ describe('BaseClient', () => {
10101042 expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/adopt/dont/shop' ) ;
10111043 } ) ;
10121044
1045+ test ( 'calls `beforeSendSpan` and uses the modified spans' , ( ) => {
1046+ expect . assertions ( 3 ) ;
1047+
1048+ const beforeSendSpan = jest . fn ( span => {
1049+ span . data = { version : 'bravo' } ;
1050+ return span ;
1051+ } ) ;
1052+
1053+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendSpan } ) ;
1054+ const client = new TestClient ( options ) ;
1055+ const transaction : Event = {
1056+ transaction : '/cats/are/great' ,
1057+ type : 'transaction' ,
1058+ spans : [
1059+ {
1060+ description : 'first span' ,
1061+ span_id : '9e15bf99fbe4bc80' ,
1062+ start_timestamp : 1591603196.637835 ,
1063+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1064+ } ,
1065+ {
1066+ description : 'second span' ,
1067+ span_id : 'aa554c1f506b0783' ,
1068+ start_timestamp : 1591603196.637835 ,
1069+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1070+ } ,
1071+ ] ,
1072+ } ;
1073+
1074+ client . captureEvent ( transaction ) ;
1075+
1076+ expect ( beforeSendSpan ) . toHaveBeenCalledTimes ( 2 ) ;
1077+ const capturedEvent = TestClient . instance ! . event ! ;
1078+ for ( const [ idx , span ] of capturedEvent . spans ! . entries ( ) ) {
1079+ const originalSpan = transaction . spans ! [ idx ] ;
1080+ expect ( span ) . toEqual ( { ...originalSpan , data : { version : 'bravo' } } ) ;
1081+ }
1082+ } ) ;
1083+
10131084 test ( 'calls `beforeSend` and discards the event' , ( ) => {
10141085 expect . assertions ( 4 ) ;
10151086
@@ -1048,6 +1119,38 @@ describe('BaseClient', () => {
10481119 expect ( loggerWarnSpy ) . toBeCalledWith ( 'before send for type `transaction` returned `null`, will not send event.' ) ;
10491120 } ) ;
10501121
1122+ test ( 'calls `beforeSendSpan` and discards the span' , ( ) => {
1123+ expect . assertions ( 2 ) ;
1124+
1125+ const beforeSendSpan = jest . fn ( ( ) => null ) ;
1126+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendSpan } ) ;
1127+ const client = new TestClient ( options ) ;
1128+
1129+ const transaction : Event = {
1130+ transaction : '/cats/are/great' ,
1131+ type : 'transaction' ,
1132+ spans : [
1133+ {
1134+ description : 'first span' ,
1135+ span_id : '9e15bf99fbe4bc80' ,
1136+ start_timestamp : 1591603196.637835 ,
1137+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1138+ } ,
1139+ {
1140+ description : 'second span' ,
1141+ span_id : 'aa554c1f506b0783' ,
1142+ start_timestamp : 1591603196.637835 ,
1143+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1144+ } ,
1145+ ] ,
1146+ } ;
1147+ client . captureEvent ( transaction ) ;
1148+
1149+ expect ( beforeSendSpan ) . toHaveBeenCalledTimes ( 2 ) ;
1150+ const capturedEvent = TestClient . instance ! . event ! ;
1151+ expect ( capturedEvent . spans ) . toHaveLength ( 0 ) ;
1152+ } ) ;
1153+
10511154 test ( 'calls `beforeSend` and logs info about invalid return value' , ( ) => {
10521155 const invalidValues = [ undefined , false , true , [ ] , 1 ] ;
10531156 expect . assertions ( invalidValues . length * 3 ) ;
0 commit comments