Skip to content

Commit b40ecae

Browse files
jpnurmiantonpirker
authored andcommitted
feat(native): support modifying attachments after init (#14019)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Adds documentation for Native SDK PR - getsentry/sentry-native#1266 > Platforms / Native / Enriching Events / Attachments ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [x] Checked Vercel preview for correctness, including links - [x] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 8aa30ce commit b40ecae

File tree

1 file changed

+33
-1
lines changed
  • platform-includes/enriching-events/add-attachment

1 file changed

+33
-1
lines changed
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1-
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:
1+
To add an attachment, you can either configure it when initializing the SDK, or manipulate the list of attachments in the scope.
2+
3+
### SDK Initialization
4+
5+
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:
26

37
```c
48
sentry_options_add_attachment(options, "/var/server.log");
59
```
10+
11+
### Adding Attachments to the Scope
12+
13+
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.
14+
15+
```c
16+
// Global Scope
17+
sentry_attach_file("/var/global.log");
18+
19+
// Local Scope
20+
sentry_scope_t *scope = sentry_local_scope_new();
21+
sentry_scope_attach_file(scope, "/var/local.log");
22+
sentry_value_t event = sentry_value_new_event();
23+
/* ... */
24+
sentry_capture_event_with_scope(event, scope);
25+
```
26+
27+
<Alert>☝ 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.</Alert>
28+
29+
### Removing Scoped Attachments
30+
31+
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.
32+
33+
```c
34+
sentry_attachment_t *attachment = sentry_attach_file("/var/temp.log");
35+
/* ... */
36+
sentry_remove_attachment(attachment);
37+
```

0 commit comments

Comments
 (0)