@@ -978,6 +978,38 @@ describe('BaseClient', () => {
978
978
expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/dogs/are/great' ) ;
979
979
} ) ;
980
980
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
+
981
1013
test ( 'calls `beforeSend` and uses the modified event' , ( ) => {
982
1014
expect . assertions ( 2 ) ;
983
1015
@@ -1010,6 +1042,45 @@ describe('BaseClient', () => {
1010
1042
expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/adopt/dont/shop' ) ;
1011
1043
} ) ;
1012
1044
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
+
1013
1084
test ( 'calls `beforeSend` and discards the event' , ( ) => {
1014
1085
expect . assertions ( 4 ) ;
1015
1086
@@ -1048,6 +1119,38 @@ describe('BaseClient', () => {
1048
1119
expect ( loggerWarnSpy ) . toBeCalledWith ( 'before send for type `transaction` returned `null`, will not send event.' ) ;
1049
1120
} ) ;
1050
1121
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
+
1051
1154
test ( 'calls `beforeSend` and logs info about invalid return value' , ( ) => {
1052
1155
const invalidValues = [ undefined , false , true , [ ] , 1 ] ;
1053
1156
expect . assertions ( invalidValues . length * 3 ) ;
0 commit comments