From 01686bdc23e3d3885763c9585500fbe2e37f92e8 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Thu, 25 Jul 2024 14:27:20 +0200 Subject: [PATCH] docs(python): Update attachment docs for 2.x Update attachment docs to reflect new API added in Python SDK 2.0.0, and introduce other general improvements to the page. Fixes: #10844 Related: getsentry/sentry-python#3340 --- .../add-attachment/python.mdx | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/platform-includes/enriching-events/add-attachment/python.mdx b/platform-includes/enriching-events/add-attachment/python.mdx index b6a173af506c29..5d37b0870eface 100644 --- a/platform-includes/enriching-events/add-attachment/python.mdx +++ b/platform-includes/enriching-events/add-attachment/python.mdx @@ -1,28 +1,27 @@ -Attachments live on the `Scope` and will be sent with all events. +Attachments live on the [`Scope`](/platforms/python/enriching-events/scopes/). The SDK sends all attachments on a given `Scope` with every non-transaction event captured within the `Scope`. Optionally, an attachment can be sent with all events, including transactions, when the attachment is added with the `add_to_transactions` option set to `True`. ```python # Add an attachment -from sentry_sdk import configure_scope +from sentry_sdk import Scope -with configure_scope() as scope: - scope.add_attachment(bytes=b"Hello World!", filename="attachment.txt") - scope.add_attachment(path="/path/to/attachment/file.txt") -``` - -An attachment has the following fields: - -`path` +# Scope.get_isolation_scope() or Scope.get_global_scope() can also be used. +# Read about the different scopes on our Scope docs page. +scope = Scope.get_current_scope() -The path to the attachment file. The `filename` and `content_type` will be inferred if not explicitly provided when using this mode. +# Add attachment titled "attachment.txt" with content "Hello World!" +scope.add_attachment(bytes=b"Hello World!", filename="attachment.txt") -`bytes` +# Attach the file located at /path/to/attachment/file.txt +scope.add_attachment(path="/path/to/attachment/file.txt") -The content of the attachment as bytes. - -`filename` - -The filename is required if using `bytes` and will be displayed in [sentry.io](https://sentry.io). +# This attachment will also be sent with transactions +scope.add_attachment(path="/other/attachment.txt", add_to_transactions=True) +``` -`content_type` -The type of content stored in this attachment. Any [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml) may be used; the default is `application/octet-stream`. +The `add_attachment` method has the following parameters: + - `bytes`: Raw bytes of the attachment, or a function that returns the raw bytes. Must be provided unless a `path` to the attachment file is provided. + - `filename`: The filename of the attachment which we display in Sentry. Optional only if a `path` is provided, since we can infer the `filename` from the `path`. + - `path`: Path to a file to attach. Must be provided unless `bytes` is provided. + - `content_type`: The attachment's [MIME type](https://www.iana.org/assignments/media-types/media-types.xhtml). If not provided, it will be guessed from the attachment's file name provided via `filename` or inferred from `path`. + - `add_to_transactions`: Whether to add this attachment to transactions. Defaults to `False`.