@@ -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,16 @@ 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.X.X
320
+
321
+ Returns the last event id of the isolation scope.
322
+ """
323
+ return cls .get_isolation_scope ()._last_event_id
324
+
311
325
def _merge_scopes (self , additional_scope = None , additional_scope_kwargs = None ):
312
326
# type: (Optional[Scope], Optional[Dict[str, Any]]) -> Scope
313
327
"""
@@ -1089,7 +1103,12 @@ def capture_event(self, event, hint=None, scope=None, **scope_kwargs):
1089
1103
"""
1090
1104
scope = self ._merge_scopes (scope , scope_kwargs )
1091
1105
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
1093
1112
1094
1113
def capture_message (self , message , level = None , scope = None , ** scope_kwargs ):
1095
1114
# type: (str, Optional[LogLevelStr], Optional[Scope], Any) -> Optional[str]
0 commit comments