@@ -1047,6 +1047,178 @@ describe('Client', () => {
10471047 expect ( capturedEvent . transaction ) . toEqual ( transaction . transaction ) ;
10481048 } ) ;
10491049
1050+ test ( 'uses `ignoreSpans` to drop root spans' , ( ) => {
1051+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , ignoreSpans : [ 'root span' ] } ) ;
1052+ const client = new TestClient ( options ) ;
1053+
1054+ const captureExceptionSpy = vi . spyOn ( client , 'captureException' ) ;
1055+ const loggerLogSpy = vi . spyOn ( debugLoggerModule . debug , 'log' ) ;
1056+
1057+ const transaction : Event = {
1058+ transaction : 'root span' ,
1059+ type : 'transaction' ,
1060+ spans : [
1061+ {
1062+ description : 'first span' ,
1063+ span_id : '9e15bf99fbe4bc80' ,
1064+ start_timestamp : 1591603196.637835 ,
1065+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1066+ data : { } ,
1067+ } ,
1068+ {
1069+ description : 'second span' ,
1070+ span_id : 'aa554c1f506b0783' ,
1071+ start_timestamp : 1591603196.637835 ,
1072+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1073+ data : { } ,
1074+ } ,
1075+ ] ,
1076+ } ;
1077+ client . captureEvent ( transaction ) ;
1078+
1079+ expect ( TestClient . instance ! . event ) . toBeUndefined ( ) ;
1080+ // This proves that the reason the event didn't send/didn't get set on the test client is not because there was an
1081+ // error, but because the event processor returned `null`
1082+ expect ( captureExceptionSpy ) . not . toBeCalled ( ) ;
1083+ expect ( loggerLogSpy ) . toBeCalledWith ( 'before send for type `transaction` returned `null`, will not send event.' ) ;
1084+ } ) ;
1085+
1086+ test ( 'uses `ignoreSpans` to drop child spans' , ( ) => {
1087+ const options = getDefaultTestClientOptions ( { dsn : PUBLIC_DSN , ignoreSpans : [ 'first span' ] } ) ;
1088+ const client = new TestClient ( options ) ;
1089+ const recordDroppedEventSpy = vi . spyOn ( client , 'recordDroppedEvent' ) ;
1090+
1091+ const transaction : Event = {
1092+ contexts : {
1093+ trace : {
1094+ span_id : 'root-span-id' ,
1095+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1096+ } ,
1097+ } ,
1098+ transaction : 'root span' ,
1099+ type : 'transaction' ,
1100+ spans : [
1101+ {
1102+ description : 'first span' ,
1103+ span_id : '9e15bf99fbe4bc80' ,
1104+ parent_span_id : 'root-span-id' ,
1105+ start_timestamp : 1591603196.637835 ,
1106+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1107+ data : { } ,
1108+ } ,
1109+ {
1110+ description : 'second span' ,
1111+ span_id : 'aa554c1f506b0783' ,
1112+ parent_span_id : 'root-span-id' ,
1113+ start_timestamp : 1591603196.637835 ,
1114+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1115+ data : { } ,
1116+ } ,
1117+ {
1118+ description : 'third span' ,
1119+ span_id : 'aa554c1f506b0783' ,
1120+ parent_span_id : '9e15bf99fbe4bc80' ,
1121+ start_timestamp : 1591603196.637835 ,
1122+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1123+ data : { } ,
1124+ } ,
1125+ ] ,
1126+ } ;
1127+ client . captureEvent ( transaction ) ;
1128+
1129+ const capturedEvent = TestClient . instance ! . event ! ;
1130+ expect ( capturedEvent . spans ) . toEqual ( [
1131+ {
1132+ description : 'second span' ,
1133+ span_id : 'aa554c1f506b0783' ,
1134+ parent_span_id : 'root-span-id' ,
1135+ start_timestamp : 1591603196.637835 ,
1136+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1137+ data : { } ,
1138+ } ,
1139+ {
1140+ description : 'third span' ,
1141+ span_id : 'aa554c1f506b0783' ,
1142+ parent_span_id : 'root-span-id' ,
1143+ start_timestamp : 1591603196.637835 ,
1144+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1145+ data : { } ,
1146+ } ,
1147+ ] ) ;
1148+ expect ( recordDroppedEventSpy ) . toBeCalledWith ( 'before_send' , 'span' , 1 ) ;
1149+ } ) ;
1150+
1151+ test ( 'uses complex `ignoreSpans` to drop child spans' , ( ) => {
1152+ const options = getDefaultTestClientOptions ( {
1153+ dsn : PUBLIC_DSN ,
1154+ ignoreSpans : [
1155+ {
1156+ name : 'first span' ,
1157+ } ,
1158+ {
1159+ name : 'span' ,
1160+ op : 'op1' ,
1161+ } ,
1162+ ] ,
1163+ } ) ;
1164+ const client = new TestClient ( options ) ;
1165+ const recordDroppedEventSpy = vi . spyOn ( client , 'recordDroppedEvent' ) ;
1166+
1167+ const transaction : Event = {
1168+ contexts : {
1169+ trace : {
1170+ span_id : 'root-span-id' ,
1171+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1172+ } ,
1173+ } ,
1174+ transaction : 'root span' ,
1175+ type : 'transaction' ,
1176+ spans : [
1177+ {
1178+ description : 'first span' ,
1179+ span_id : '9e15bf99fbe4bc80' ,
1180+ parent_span_id : 'root-span-id' ,
1181+ start_timestamp : 1591603196.637835 ,
1182+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1183+ data : { } ,
1184+ } ,
1185+ {
1186+ description : 'second span' ,
1187+ op : 'op1' ,
1188+ span_id : 'aa554c1f506b0783' ,
1189+ parent_span_id : 'root-span-id' ,
1190+ start_timestamp : 1591603196.637835 ,
1191+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1192+ data : { } ,
1193+ } ,
1194+ {
1195+ description : 'third span' ,
1196+ op : 'other op' ,
1197+ span_id : 'aa554c1f506b0783' ,
1198+ parent_span_id : '9e15bf99fbe4bc80' ,
1199+ start_timestamp : 1591603196.637835 ,
1200+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1201+ data : { } ,
1202+ } ,
1203+ ] ,
1204+ } ;
1205+ client . captureEvent ( transaction ) ;
1206+
1207+ const capturedEvent = TestClient . instance ! . event ! ;
1208+ expect ( capturedEvent . spans ) . toEqual ( [
1209+ {
1210+ description : 'third span' ,
1211+ op : 'other op' ,
1212+ span_id : 'aa554c1f506b0783' ,
1213+ parent_span_id : 'root-span-id' ,
1214+ start_timestamp : 1591603196.637835 ,
1215+ trace_id : '86f39e84263a4de99c326acab3bfe3bd' ,
1216+ data : { } ,
1217+ } ,
1218+ ] ) ;
1219+ expect ( recordDroppedEventSpy ) . toBeCalledWith ( 'before_send' , 'span' , 2 ) ;
1220+ } ) ;
1221+
10501222 test ( 'does not modify existing contexts for root span in `beforeSendSpan`' , ( ) => {
10511223 const beforeSendSpan = vi . fn ( ( span : SpanJSON ) => {
10521224 return {
0 commit comments