@@ -185,6 +185,7 @@ class Scope(object):
185185 "_propagation_context" ,
186186 "client" ,
187187 "_type" ,
188+ "_last_event_id" ,
188189 )
189190
190191 def __init__ (self , ty = None , client = None ):
@@ -207,6 +208,9 @@ def __init__(self, ty=None, client=None):
207208 incoming_trace_information = self ._load_trace_data_from_env ()
208209 self .generate_propagation_context (incoming_data = incoming_trace_information )
209210
211+ # self._last_event_id is only applicable to isolation scopes
212+ self ._last_event_id = None # type: Optional[str]
213+
210214 def __copy__ (self ):
211215 # type: () -> Scope
212216 """
@@ -308,6 +312,16 @@ def get_global_scope(cls):
308312
309313 return _global_scope
310314
315+ @classmethod
316+ def last_event_id (cls ):
317+ # type: () -> Optional[str]
318+ """
319+ .. versionadded:: 2.X.X
320+
321+ Returns the last event id of the isolation scope.
322+ """
323+ return cls .get_isolation_scope ()._last_event_id
324+
311325 def _merge_scopes (self , additional_scope = None , additional_scope_kwargs = None ):
312326 # type: (Optional[Scope], Optional[Dict[str, Any]]) -> Scope
313327 """
@@ -1089,7 +1103,12 @@ def capture_event(self, event, hint=None, scope=None, **scope_kwargs):
10891103 """
10901104 scope = self ._merge_scopes (scope , scope_kwargs )
10911105
1092- return Scope .get_client ().capture_event (event = event , hint = hint , scope = scope )
1106+ event_id = Scope .get_client ().capture_event (event = event , hint = hint , scope = scope )
1107+
1108+ if event_id is not None and event .get ("type" ) != "transaction" :
1109+ self .get_isolation_scope ()._last_event_id = event_id
1110+
1111+ return event_id
10931112
10941113 def capture_message (self , message , level = None , scope = None , ** scope_kwargs ):
10951114 # type: (str, Optional[LogLevelStr], Optional[Scope], Any) -> Optional[str]
0 commit comments