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