Skip to content

docs(attachment): Document attachment parameters #3342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions sentry_sdk/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@


class Attachment:
"""Additional files/data to send along with an event.

This class stores attachments that can be sent along with an event. Attachments are files or other data, e.g.
config or log files, that are relevant to an event. Attachments are set on the ``Scope``, and are sent along with
all non-transaction events (or all events including transactions if ``add_to_transactions`` is ``True``) that are
captured within the ``Scope``.

To add an attachment to a ``Scope``, use :py:meth:`sentry_sdk.Scope.add_attachment`. The parameters for
``add_attachment`` are the same as the parameters for this class's constructor.

:param bytes: Raw bytes of the attachment, or a function that returns the raw bytes. Must be provided unless
``path`` is provided.
:param filename: The filename of the attachment. Must be provided unless ``path`` is provided.
:param path: Path to a file to attach. Must be provided unless ``bytes`` is provided.
:param content_type: The content type of the attachment. If not provided, it will be guessed from the ``filename``
parameter, if available, or the ``path`` parameter if ``filename`` is ``None``.
:param add_to_transactions: Whether to add this attachment to transactions. Defaults to ``False``.
"""

def __init__(
self,
bytes=None, # type: Union[None, bytes, Callable[[], bytes]]
Expand Down
7 changes: 5 additions & 2 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,14 +893,17 @@ def clear_breadcrumbs(self):

def add_attachment(
self,
bytes=None, # type: Optional[bytes]
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
"""Adds an attachment to future events sent."""
"""Adds an attachment to future events sent from this scope.

The parameters are the same as for the :py:class:`sentry_sdk.attachments.Attachment` constructor.
"""
self._attachments.append(
Attachment(
bytes=bytes,
Expand Down
Loading