From 52e4583564d7a8c38c6aa826139741f15a6cb19f Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 May 2025 12:15:05 +0200 Subject: [PATCH 1/3] Add a top level API for add_attachment --- sentry_sdk/__init__.py | 1 + sentry_sdk/api.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/sentry_sdk/__init__.py b/sentry_sdk/__init__.py index b35c446dc0..55f2256e3b 100644 --- a/sentry_sdk/__init__.py +++ b/sentry_sdk/__init__.py @@ -16,6 +16,7 @@ "integrations", # From sentry_sdk.api "init", + "add_attachment", "add_breadcrumb", "capture_event", "capture_exception", diff --git a/sentry_sdk/api.py b/sentry_sdk/api.py index b8a2498d5d..418afe6a8f 100644 --- a/sentry_sdk/api.py +++ b/sentry_sdk/api.py @@ -39,6 +39,7 @@ # When changing this, update __all__ in __init__.py too __all__ = [ "init", + "add_attachment", "add_breadcrumb", "capture_event", "capture_exception", @@ -171,6 +172,20 @@ def capture_exception( return get_current_scope().capture_exception(error, scope=scope, **scope_kwargs) +@scopemethod +def add_attachment( + bytes=None, # type: Union[None, bytes, Callable[[], bytes]] + filename=None, # type: Optional[str] + path=None, # type: Optional[str] + content_type=None, # type: Optional[str] + add_to_transactions=False, # type: bool +): + # type: (...) -> None + return get_isolation_scope().add_attachment( + bytes, filename, path, content_type, add_to_transactions + ) + + @scopemethod def add_breadcrumb( crumb=None, # type: Optional[sentry_sdk._types.Breadcrumb] From 36da125df8f3be3ad6a0eca5dd8f6e30eab0458c Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 May 2025 12:34:49 +0200 Subject: [PATCH 2/3] Apidocs --- docs/api.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/api.rst b/docs/api.rst index 95acc70455..f79eed0cbb 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -25,6 +25,7 @@ Capturing Data Enriching Events ================ +.. autofunction:: sentry_sdk.api.add_attachment .. autofunction:: sentry_sdk.api.add_breadcrumb .. autofunction:: sentry_sdk.api.set_context .. autofunction:: sentry_sdk.api.set_extra From d952f46b69a5ef74657331f474120b69a1a3a10a Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 5 May 2025 14:43:55 +0200 Subject: [PATCH 3/3] Added add_attachment to migration guide --- MIGRATION_GUIDE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 8e375c5d20..5c2402e07f 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -6,6 +6,8 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh ### New Features +- Added `add_attachment()` as a top level API, so you can do now: `sentry_sdk.add_attachment(...)` (up until now it was only available on the `Scope`) + ### Changed - The SDK now supports Python 3.7 and higher.