Skip to content

Commit 0d7a6f7

Browse files
feat: Add last_event_id to top-level api
ref #3049
1 parent 92a3698 commit 0d7a6f7

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

sentry_sdk/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"get_traceparent",
3434
"is_initialized",
3535
"isolation_scope",
36+
"last_event_id",
3637
"new_scope",
3738
"push_scope",
3839
"set_context",

sentry_sdk/api.py

+11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def overload(x):
5959
"get_traceparent",
6060
"is_initialized",
6161
"isolation_scope",
62+
"last_event_id",
6263
"new_scope",
6364
"push_scope",
6465
"set_context",
@@ -332,6 +333,16 @@ def start_transaction(
332333
)
333334

334335

336+
@scopemethod
337+
def last_event_id():
338+
# type: () -> Optional[str]
339+
"""
340+
See :py:meth:`sentry_sdk.Scope.last_event_id` documentation regarding
341+
this method's limitations.
342+
"""
343+
return Scope.last_event_id()
344+
345+
335346
def set_measurement(name, value, unit=""):
336347
# type: (str, float, MeasurementUnit) -> None
337348
transaction = Scope.get_current_scope().transaction

tests/test_basics.py

+22
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
capture_exception,
1616
capture_message,
1717
start_transaction,
18+
last_event_id,
1819
add_breadcrumb,
1920
Hub,
2021
Scope,
@@ -778,3 +779,24 @@ def test_classmethod_tracing(sentry_init):
778779
with patch_start_tracing_child() as fake_start_child:
779780
assert instance_or_class.class_(1) == (TracingTestClass, 1)
780781
assert fake_start_child.call_count == 1
782+
783+
784+
def test_last_event_id(sentry_init):
785+
sentry_init(enable_tracing=True)
786+
787+
assert last_event_id() is None
788+
789+
capture_exception(Exception("test"))
790+
791+
assert last_event_id() is not None
792+
793+
794+
def test_last_event_id_transaction(sentry_init):
795+
sentry_init(enable_tracing=True)
796+
797+
assert last_event_id() is None
798+
799+
with start_transaction(name="test"):
800+
pass
801+
802+
assert last_event_id() is None, "Transaction should not set last_event_id"

0 commit comments

Comments
 (0)