Skip to content

Commit

Permalink
docs: Document attachment parameters (getsentry#3342)
Browse files Browse the repository at this point in the history
Document parameters to `sentry_sdk.Scope.add_attachment` and
`sentry_sdk.attachments.Attachment`.

Fixes: getsentry#3340
Related: getsentry/sentry-docs#10844
  • Loading branch information
szokeasaurusrex authored and arjenzorgdoc committed Sep 30, 2024
1 parent 82fdb63 commit 446b93d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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
5 changes: 4 additions & 1 deletion sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,10 @@ def add_attachment(
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

0 comments on commit 446b93d

Please # to comment.