diff --git a/platform-includes/enriching-events/add-attachment/native.mdx b/platform-includes/enriching-events/add-attachment/native.mdx index b9ef15aa460364..31026a2680eb46 100644 --- a/platform-includes/enriching-events/add-attachment/native.mdx +++ b/platform-includes/enriching-events/add-attachment/native.mdx @@ -1,5 +1,37 @@ -To add an attachment, the path to the file has to be configured when initializing the SDK. It will monitor the file and upload it along with any event or crash that is sent to Sentry: +To add an attachment, you can either configure it when initializing the SDK, or manipulate the list of attachments in the scope. + +### SDK Initialization + +Adding attachments to the options during SDK initialization will monitor the file and upload it along with any event or crash that is sent to Sentry: ```c sentry_options_add_attachment(options, "/var/server.log"); ``` + +### Adding Attachments to the Scope + +Adding attachments to the global scope at run-time after SDK initialization will monitor the file and upload it along with any event or crash that is sent to Sentry, whereas adding attachments to a local scope will only upload the file with the specific event captured in that local scope. + +```c +// Global Scope +sentry_attach_file("/var/global.log"); + +// Local Scope +sentry_scope_t *scope = sentry_local_scope_new(); +sentry_scope_attach_file(scope, "/var/local.log"); +sentry_value_t event = sentry_value_new_event(); +/* ... */ +sentry_capture_event_with_scope(event, scope); +``` + +☝ When using the `crashpad` backend on macOS, the list of attachments that will be added at the time of a hard crash will be frozen at the time of `sentry_init`, and later modifications will not be reflected. + +### Removing Scoped Attachments + +To remove attachments from the global scope, you can use the `sentry_attachment_t` handle returned by `sentry_attach_file`. After removing the attachment, the file will no longer be uploaded with any future events or crashes and the handle becomes invalid. + +```c +sentry_attachment_t *attachment = sentry_attach_file("/var/temp.log"); +/* ... */ +sentry_remove_attachment(attachment); +```