Skip to content

Commit

Permalink
feat: Add last_event_id to top-level api
Browse files Browse the repository at this point in the history
ref #3049
  • Loading branch information
szokeasaurusrex committed May 15, 2024
1 parent 92a3698 commit 0d7a6f7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions sentry_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"get_traceparent",
"is_initialized",
"isolation_scope",
"last_event_id",
"new_scope",
"push_scope",
"set_context",
Expand Down
11 changes: 11 additions & 0 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def overload(x):
"get_traceparent",
"is_initialized",
"isolation_scope",
"last_event_id",
"new_scope",
"push_scope",
"set_context",
Expand Down Expand Up @@ -332,6 +333,16 @@ def start_transaction(
)


@scopemethod
def last_event_id():
# type: () -> Optional[str]
"""
See :py:meth:`sentry_sdk.Scope.last_event_id` documentation regarding
this method's limitations.
"""
return Scope.last_event_id()


def set_measurement(name, value, unit=""):
# type: (str, float, MeasurementUnit) -> None
transaction = Scope.get_current_scope().transaction
Expand Down
22 changes: 22 additions & 0 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
capture_exception,
capture_message,
start_transaction,
last_event_id,
add_breadcrumb,
Hub,
Scope,
Expand Down Expand Up @@ -778,3 +779,24 @@ def test_classmethod_tracing(sentry_init):
with patch_start_tracing_child() as fake_start_child:
assert instance_or_class.class_(1) == (TracingTestClass, 1)
assert fake_start_child.call_count == 1


def test_last_event_id(sentry_init):
sentry_init(enable_tracing=True)

assert last_event_id() is None

capture_exception(Exception("test"))

assert last_event_id() is not None


def test_last_event_id_transaction(sentry_init):
sentry_init(enable_tracing=True)

assert last_event_id() is None

with start_transaction(name="test"):
pass

assert last_event_id() is None, "Transaction should not set last_event_id"

0 comments on commit 0d7a6f7

Please sign in to comment.