Skip to content

Commit

Permalink
feat(client): Add last_event_id to Client
Browse files Browse the repository at this point in the history
ref #3049
  • Loading branch information
szokeasaurusrex committed May 8, 2024
1 parent 6148f07 commit 978fa06
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ def flush(self, *args, **kwargs):
# type: (*Any, **Any) -> None
return None

def last_event_id(self):
# type: () -> Optional[str]
"""
.. versionadded:: 2.1.2
Returns the most recently captured error event's ID. If this client has
not captured an error event yet, returns `None`.
"""
return None

def __enter__(self):
# type: () -> BaseClient
return self
Expand Down Expand Up @@ -379,6 +389,8 @@ def _capture_envelope(envelope):
except Exception as e:
logger.debug("Can not set up profiler. (%s)", e)

self._last_event_id = None

finally:
_client_init_debug.set(old_debug)

Expand Down Expand Up @@ -709,6 +721,7 @@ def capture_event(

is_transaction = event_opt.get("type") == "transaction"
is_checkin = event_opt.get("type") == "check_in"
is_error = not is_transaction and not is_checkin

if (
not is_transaction
Expand Down Expand Up @@ -750,6 +763,9 @@ def capture_event(
if self.transport is None:
return None

if is_error:
self._last_event_id = event_id

self.transport.capture_envelope(envelope)

return event_id
Expand Down Expand Up @@ -820,6 +836,10 @@ def flush(
self.metrics_aggregator.flush()
self.transport.flush(timeout=timeout, callback=callback)

def last_event_id(self):
# type: () -> Optional[str]
return self._last_event_id

def __enter__(self):
# type: () -> _Client
return self
Expand Down

0 comments on commit 978fa06

Please sign in to comment.