@@ -133,10 +133,23 @@ def record_lost_event(
133133 reason , # type: str
134134 data_category = None , # type: Optional[EventDataCategory]
135135 item = None , # type: Optional[Item]
136+ * ,
137+ quantity = 1 , # type: int
136138 ):
137139 # type: (...) -> None
138140 """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.
140153 """
141154 return None
142155
@@ -224,15 +237,26 @@ def record_lost_event(
224237 reason , # type: str
225238 data_category = None , # type: Optional[EventDataCategory]
226239 item = None , # type: Optional[Item]
240+ * ,
241+ quantity = 1 , # type: int
227242 ):
228243 # type: (...) -> None
229244 if not self .options ["send_client_reports" ]:
230245 return
231246
232- quantity = 1
233247 if item is not None :
234248 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" :
236260 # quantity of 0 is actually 1 as we do not want to count
237261 # empty attachments as actually empty.
238262 quantity = len (item .get_bytes ()) or 1
0 commit comments