@@ -1042,6 +1042,30 @@ describe('BaseClient', () => {
1042
1042
expect ( TestClient . instance ! . event ! . transaction ) . toBe ( '/adopt/dont/shop' ) ;
1043
1043
} ) ;
1044
1044
1045
+ test ( 'calls `beforeSendTransaction` and drops spans' , ( ) => {
1046
+ const beforeSendTransaction = jest . fn ( event => {
1047
+ event . spans = [ { span_id : 'span5' , trace_id : 'trace1' , start_timestamp : 1234 } ] ;
1048
+ return event ;
1049
+ } ) ;
1050
+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendTransaction } ) ;
1051
+ const client = new TestClient ( options ) ;
1052
+
1053
+ client . captureEvent ( {
1054
+ transaction : '/dogs/are/great' ,
1055
+ type : 'transaction' ,
1056
+ spans : [
1057
+ { span_id : 'span1' , trace_id : 'trace1' , start_timestamp : 1234 } ,
1058
+ { span_id : 'span2' , trace_id : 'trace1' , start_timestamp : 1234 } ,
1059
+ { span_id : 'span3' , trace_id : 'trace1' , start_timestamp : 1234 } ,
1060
+ ] ,
1061
+ } ) ;
1062
+
1063
+ expect ( beforeSendTransaction ) . toHaveBeenCalled ( ) ;
1064
+ expect ( TestClient . instance ! . event ! . spans ?. length ) . toBe ( 1 ) ;
1065
+
1066
+ expect ( client [ '_outcomes' ] ) . toEqual ( { 'before_send:span' : 2 } ) ;
1067
+ } ) ;
1068
+
1045
1069
test ( 'calls `beforeSendSpan` and uses the modified spans' , ( ) => {
1046
1070
expect . assertions ( 3 ) ;
1047
1071
@@ -1120,8 +1144,6 @@ describe('BaseClient', () => {
1120
1144
} ) ;
1121
1145
1122
1146
test ( 'calls `beforeSendSpan` and discards the span' , ( ) => {
1123
- expect . assertions ( 2 ) ;
1124
-
1125
1147
const beforeSendSpan = jest . fn ( ( ) => null ) ;
1126
1148
const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , beforeSendSpan } ) ;
1127
1149
const client = new TestClient ( options ) ;
@@ -1149,6 +1171,7 @@ describe('BaseClient', () => {
1149
1171
expect ( beforeSendSpan ) . toHaveBeenCalledTimes ( 2 ) ;
1150
1172
const capturedEvent = TestClient . instance ! . event ! ;
1151
1173
expect ( capturedEvent . spans ) . toHaveLength ( 0 ) ;
1174
+ expect ( client [ '_outcomes' ] ) . toEqual ( { 'before_send:span' : 2 } ) ;
1152
1175
} ) ;
1153
1176
1154
1177
test ( 'calls `beforeSend` and logs info about invalid return value' , ( ) => {
@@ -2017,6 +2040,7 @@ describe('BaseClient', () => {
2017
2040
2018
2041
describe ( 'hook removal with `on`' , ( ) => {
2019
2042
it ( 'should return a cleanup function that, when executed, unregisters a hook' , async ( ) => {
2043
+ jest . useFakeTimers ( ) ;
2020
2044
expect . assertions ( 8 ) ;
2021
2045
2022
2046
const client = new TestClient (
0 commit comments