@@ -185,6 +185,7 @@ class Scope(object):
185
185
"_propagation_context" ,
186
186
"client" ,
187
187
"_type" ,
188
+ "_last_event_id" ,
188
189
)
189
190
190
191
def __init__ (self , ty = None , client = None ):
@@ -207,6 +208,9 @@ def __init__(self, ty=None, client=None):
207
208
incoming_trace_information = self ._load_trace_data_from_env ()
208
209
self .generate_propagation_context (incoming_data = incoming_trace_information )
209
210
211
+ # self._last_event_id is only applicable to isolation scopes
212
+ self ._last_event_id = None # type: Optional[str]
213
+
210
214
def __copy__ (self ):
211
215
# type: () -> Scope
212
216
"""
@@ -308,6 +312,23 @@ def get_global_scope(cls):
308
312
309
313
return _global_scope
310
314
315
+ @classmethod
316
+ def last_event_id (cls ):
317
+ # type: () -> Optional[str]
318
+ """
319
+ .. versionadded:: 2.2.0
320
+
321
+ Returns event ID of the event most recently captured by the isolation scope, or None if no event
322
+ has been captured. We do not consider events that are dropped, e.g. by a before_send hook.
323
+ Transactions also are not considered events in this context.
324
+
325
+ The event corresponding to the returned event ID is NOT guaranteed to actually be sent to Sentry;
326
+ whether the event is sent depends on the transport. The event could be sent later or not at all.
327
+ Even a sent event could fail to arrive in Sentry due to network issues, exhausted quotas, or
328
+ various other reasons.
329
+ """
330
+ return cls .get_isolation_scope ()._last_event_id
331
+
311
332
def _merge_scopes (self , additional_scope = None , additional_scope_kwargs = None ):
312
333
# type: (Optional[Scope], Optional[Dict[str, Any]]) -> Scope
313
334
"""
@@ -1089,7 +1110,12 @@ def capture_event(self, event, hint=None, scope=None, **scope_kwargs):
1089
1110
"""
1090
1111
scope = self ._merge_scopes (scope , scope_kwargs )
1091
1112
1092
- return Scope .get_client ().capture_event (event = event , hint = hint , scope = scope )
1113
+ event_id = Scope .get_client ().capture_event (event = event , hint = hint , scope = scope )
1114
+
1115
+ if event_id is not None and event .get ("type" ) != "transaction" :
1116
+ self .get_isolation_scope ()._last_event_id = event_id
1117
+
1118
+ return event_id
1093
1119
1094
1120
def capture_message (self , message , level = None , scope = None , ** scope_kwargs ):
1095
1121
# type: (str, Optional[LogLevelStr], Optional[Scope], Any) -> Optional[str]
0 commit comments