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. 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 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]