@@ -947,6 +947,38 @@ describe('BaseClient', () => {
947947 expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/dogs/are/great' ) ;
948948 } ) ;
949949
950+ test ( 'calls `beforeSendSpan` and uses original spans without any changes' , ( ) => {
951+ expect . assertions ( 2 ) ;
952+
953+ const beforeSendSpan = jest . fn ( span => span ) ;
954+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendSpan } ) ;
955+ const client = new TestClient ( options ) ;
956+
957+ const transaction : Event = {
958+ transaction : '/cats/are/great' ,
959+ type : 'transaction' ,
960+ spans : [
961+ {
962+ description : 'first span' ,
963+ span_id : '9e15bf99fbe4bc80' ,
964+ start_timestamp : 1591603196.637835 ,
965+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
966+ } ,
967+ {
968+ description : 'second span' ,
969+ span_id : 'aa554c1f506b0783' ,
970+ start_timestamp : 1591603196.637835 ,
971+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
972+ } ,
973+ ] ,
974+ } ;
975+ client . captureEvent ( transaction ) ;
976+
977+ expect ( beforeSendSpan ) . toHaveBeenCalledTimes ( 2 ) ;
978+ const capturedEvent = TestClient . instance ! . event ! ;
979+ expect ( capturedEvent . spans ) . toEqual ( transaction . spans ) ;
980+ } ) ;
981+
950982 test ( 'calls `beforeSend` and uses the modified event' , ( ) => {
951983 expect . assertions ( 2 ) ;
952984
@@ -979,6 +1011,45 @@ describe('BaseClient', () => {
9791011 expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/adopt/dont/shop' ) ;
9801012 } ) ;
9811013
1014+ test ( 'calls `beforeSendSpan` and uses the modified spans' , ( ) => {
1015+ expect . assertions ( 3 ) ;
1016+
1017+ const beforeSendSpan = jest . fn ( span => {
1018+ span . data = { version : 'bravo' } ;
1019+ return span ;
1020+ } ) ;
1021+
1022+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendSpan } ) ;
1023+ const client = new TestClient ( options ) ;
1024+ const transaction : Event = {
1025+ transaction : '/cats/are/great' ,
1026+ type : 'transaction' ,
1027+ spans : [
1028+ {
1029+ description : 'first span' ,
1030+ span_id : '9e15bf99fbe4bc80' ,
1031+ start_timestamp : 1591603196.637835 ,
1032+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1033+ } ,
1034+ {
1035+ description : 'second span' ,
1036+ span_id : 'aa554c1f506b0783' ,
1037+ start_timestamp : 1591603196.637835 ,
1038+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1039+ } ,
1040+ ] ,
1041+ } ;
1042+
1043+ client . captureEvent ( transaction ) ;
1044+
1045+ expect ( beforeSendSpan ) . toHaveBeenCalledTimes ( 2 ) ;
1046+ const capturedEvent = TestClient . instance ! . event ! ;
1047+ for ( const [ idx , span ] of capturedEvent . spans ! . entries ( ) ) {
1048+ const originalSpan = transaction . spans ! [ idx ] ;
1049+ expect ( span ) . toEqual ( { ...originalSpan , data : { version : 'bravo' } } ) ;
1050+ }
1051+ } ) ;
1052+
9821053 test ( 'calls `beforeSend` and discards the event' , ( ) => {
9831054 expect . assertions ( 4 ) ;
9841055
0 commit comments