From 5254558827c9465f9e09ccc5561c83953d932a01 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 12 Jun 2025 16:28:43 +0200 Subject: [PATCH 1/3] feat(native): support modifying attachments after init --- .../add-attachment/native.mdx | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/platform-includes/enriching-events/add-attachment/native.mdx b/platform-includes/enriching-events/add-attachment/native.mdx index b9ef15aa46036..1a2cd79d36e45 100644 --- a/platform-includes/enriching-events/add-attachment/native.mdx +++ b/platform-includes/enriching-events/add-attachment/native.mdx @@ -1,5 +1,27 @@ -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 during SDK initialization is supported on all platforms. It 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"); ``` + +### Global Scope + +Adding attachments to the global scope at run-time after SDK initialization is supported on Windows and Linux. It will monitor the file and upload it along with any event or crash that is sent to Sentry: + +```c +sentry_add_attachment_path("/var/server.log"); +``` + +### Local Scope + +Adding attachments to local scopes is supported on Windows and Linux. It will upload the file along with the specific event captured in the local scope: + +```c +sentry_scope_t *scope = sentry_local_scope_new(); +sentry_scope_add_attachment_path(scope, "/var/server.log"); +sentry_capture_event_with_scope(event, scope); +``` From 3492ab77963e2c3391786a1dba163f9aa25f4f1e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 13 Jun 2025 10:14:18 +0200 Subject: [PATCH 2/3] Rephrase and adapt to API changes --- .../add-attachment/native.mdx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/platform-includes/enriching-events/add-attachment/native.mdx b/platform-includes/enriching-events/add-attachment/native.mdx index 1a2cd79d36e45..e25393dac82f4 100644 --- a/platform-includes/enriching-events/add-attachment/native.mdx +++ b/platform-includes/enriching-events/add-attachment/native.mdx @@ -2,26 +2,26 @@ To add an attachment, you can either configure it when initializing the SDK, or ### SDK Initialization -Adding attachments during SDK initialization is supported on all platforms. It will monitor the file and upload it along with any event or crash that is sent to Sentry: +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"); ``` -### Global Scope +### Adding Attachments to the Scope -Adding attachments to the global scope at run-time after SDK initialization is supported on Windows and Linux. It will monitor the file and upload it along with any event or crash that is sent to Sentry: +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 -sentry_add_attachment_path("/var/server.log"); -``` - -### Local Scope - -Adding attachments to local scopes is supported on Windows and Linux. It will upload the file along with the specific event captured in the local scope: +// Global Scope +sentry_attach_file("/var/global.log"); -```c +// Local Scope sentry_scope_t *scope = sentry_local_scope_new(); -sentry_scope_add_attachment_path(scope, "/var/server.log"); +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. From 528a538f58713a09903b8992741eaab848575d07 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 13 Jun 2025 12:20:42 +0200 Subject: [PATCH 3/3] Removing Scoped Attachments --- .../enriching-events/add-attachment/native.mdx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/platform-includes/enriching-events/add-attachment/native.mdx b/platform-includes/enriching-events/add-attachment/native.mdx index e25393dac82f4..31026a2680eb4 100644 --- a/platform-includes/enriching-events/add-attachment/native.mdx +++ b/platform-includes/enriching-events/add-attachment/native.mdx @@ -25,3 +25,13 @@ 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); +```