Skip to content

Commit e635af7

Browse files
authored
Add add_attachment() top level API (#4364)
Users should not need to get the Scope and add the attachment there, we can do it for them. This has been first [implemented in SDK 3.0](#4360) and is now back ported to 2.x.
1 parent 5360744 commit e635af7

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

docs/api.rst

+1-1
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
@@ -63,4 +64,3 @@ Managing Scope (advanced)
6364
.. autofunction:: sentry_sdk.api.push_scope
6465

6566
.. autofunction:: sentry_sdk.api.new_scope
66-

sentry_sdk/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"integrations",
1616
# From sentry_sdk.api
1717
"init",
18+
"add_attachment",
1819
"add_breadcrumb",
1920
"capture_event",
2021
"capture_exception",

sentry_sdk/api.py

+15
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def overload(x):
5151
# When changing this, update __all__ in __init__.py too
5252
__all__ = [
5353
"init",
54+
"add_attachment",
5455
"add_breadcrumb",
5556
"capture_event",
5657
"capture_exception",
@@ -184,6 +185,20 @@ def capture_exception(
184185
return get_current_scope().capture_exception(error, scope=scope, **scope_kwargs)
185186

186187

188+
@scopemethod
189+
def add_attachment(
190+
bytes=None, # type: Union[None, bytes, Callable[[], bytes]]
191+
filename=None, # type: Optional[str]
192+
path=None, # type: Optional[str]
193+
content_type=None, # type: Optional[str]
194+
add_to_transactions=False, # type: bool
195+
):
196+
# type: (...) -> None
197+
return get_isolation_scope().add_attachment(
198+
bytes, filename, path, content_type, add_to_transactions
199+
)
200+
201+
187202
@scopemethod
188203
def add_breadcrumb(
189204
crumb=None, # type: Optional[Breadcrumb]

0 commit comments

Comments
 (0)