@@ -133,10 +133,23 @@ def record_lost_event(
133
133
reason , # type: str
134
134
data_category = None , # type: Optional[EventDataCategory]
135
135
item = None , # type: Optional[Item]
136
+ * ,
137
+ quantity = 1 , # type: int
136
138
):
137
139
# type: (...) -> None
138
140
"""This increments a counter for event loss by reason and
139
- data category.
141
+ data category by the given positive-int quantity (default 1).
142
+
143
+ If an item is provided, the data category and quantity are
144
+ extracted from the item, and the values passed for
145
+ data_category and quantity are ignored.
146
+
147
+ When recording a lost transaction via data_category="transaction",
148
+ the calling code should also record the lost spans via this method.
149
+ When recording lost spans, `quantity` should be set to the number
150
+ of contained spans, plus one for the transaction itself. When
151
+ passing an Item containing a transaction via the `item` parameter,
152
+ this method automatically records the lost spans.
140
153
"""
141
154
return None
142
155
@@ -224,15 +237,26 @@ def record_lost_event(
224
237
reason , # type: str
225
238
data_category = None , # type: Optional[EventDataCategory]
226
239
item = None , # type: Optional[Item]
240
+ * ,
241
+ quantity = 1 , # type: int
227
242
):
228
243
# type: (...) -> None
229
244
if not self .options ["send_client_reports" ]:
230
245
return
231
246
232
- quantity = 1
233
247
if item is not None :
234
248
data_category = item .data_category
235
- if data_category == "attachment" :
249
+ quantity = 1 # If an item is provided, we always count it as 1 (except for attachments, handled below).
250
+
251
+ if data_category == "transaction" :
252
+ # Also record the lost spans
253
+ event = item .get_transaction_event () or {}
254
+
255
+ # +1 for the transaction itself
256
+ span_count = len (event .get ("spans" ) or []) + 1
257
+ self .record_lost_event (reason , "span" , quantity = span_count )
258
+
259
+ elif data_category == "attachment" :
236
260
# quantity of 0 is actually 1 as we do not want to count
237
261
# empty attachments as actually empty.
238
262
quantity = len (item .get_bytes ()) or 1
0 commit comments