Skip to content

Commit 83e99e1

Browse files
authored
Add top level API for add_atttachment. (#4360)
This PR also needs an update of the docs to make sure people use the top level API. See this docs issue: getsentry/sentry-docs#13592
1 parent a88dadf commit 83e99e1

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

MIGRATION_GUIDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
66

77
### New Features
88

9+
- 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`)
10+
911
### Changed
1012

1113
- The SDK now supports Python 3.7 and higher.

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Capturing Data
2525
Enriching Events
2626
================
2727

28+
.. autofunction:: sentry_sdk.api.add_attachment
2829
.. autofunction:: sentry_sdk.api.add_breadcrumb
2930
.. autofunction:: sentry_sdk.api.set_context
3031
.. autofunction:: sentry_sdk.api.set_extra

sentry_sdk/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"integrations",
1717
# From sentry_sdk.api
1818
"init",
19+
"add_attachment",
1920
"add_breadcrumb",
2021
"capture_event",
2122
"capture_exception",

sentry_sdk/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# When changing this, update __all__ in __init__.py too
4040
__all__ = [
4141
"init",
42+
"add_attachment",
4243
"add_breadcrumb",
4344
"capture_event",
4445
"capture_exception",
@@ -171,6 +172,20 @@ def capture_exception(
171172
return get_current_scope().capture_exception(error, scope=scope, **scope_kwargs)
172173

173174

175+
@scopemethod
176+
def add_attachment(
177+
bytes=None, # type: Union[None, bytes, Callable[[], bytes]]
178+
filename=None, # type: Optional[str]
179+
path=None, # type: Optional[str]
180+
content_type=None, # type: Optional[str]
181+
add_to_transactions=False, # type: bool
182+
):
183+
# type: (...) -> None
184+
return get_isolation_scope().add_attachment(
185+
bytes, filename, path, content_type, add_to_transactions
186+
)
187+
188+
174189
@scopemethod
175190
def add_breadcrumb(
176191
crumb=None, # type: Optional[sentry_sdk._types.Breadcrumb]

0 commit comments

Comments
 (0)