@@ -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]
@@ -1117,7 +1136,12 @@ def capture_message(self, message, level=None, scope=None, **scope_kwargs):
1117
1136
"level" : level ,
1118
1137
} # type: Event
1119
1138
1120
- return self .capture_event (event , scope = scope , ** scope_kwargs )
1139
+ event_id = self .capture_event (event , scope = scope , ** scope_kwargs )
1140
+
1141
+ if event_id is not None :
1142
+ self .get_isolation_scope ()._last_event_id = event_id
1143
+
1144
+ return event_id
1121
1145
1122
1146
def capture_exception (self , error = None , scope = None , ** scope_kwargs ):
1123
1147
# type: (Optional[Union[BaseException, ExcInfo]], Optional[Scope], Any) -> Optional[str]
@@ -1144,11 +1168,15 @@ def capture_exception(self, error=None, scope=None, **scope_kwargs):
1144
1168
)
1145
1169
1146
1170
try :
1147
- return self .capture_event (event , hint = hint , scope = scope , ** scope_kwargs )
1171
+ event_id = self .capture_event (event , hint = hint , scope = scope , ** scope_kwargs )
1148
1172
except Exception :
1149
1173
self ._capture_internal_exception (sys .exc_info ())
1174
+ return None
1150
1175
1151
- return None
1176
+ if event_id is not None :
1177
+ self .get_isolation_scope ()._last_event_id = event_id
1178
+
1179
+ return event_id
1152
1180
1153
1181
def _capture_internal_exception (
1154
1182
self , exc_info # type: Any
0 commit comments