Add ability to set attachments on a sentry event
:scroll: Description
This just exposes a property on the event which will allow the user to add attachments to be sent.
:bulb: Motivation and Context
This is so I can add log data along with crashes. Its incredibly necessary in resolving not so obvious bugs.
:green_heart: How did you test it?
It's currently live in our app and seems to work.
:pencil: Checklist
You have to check all boxes before merging:
- [ ] I reviewed the submitted code.
- [ ] I added tests to verify the changes.
- [ ] No new PII added or SDK only sends newly added PII if
sendDefaultPIIis enabled. - [ ] I updated the docs if needed.
- [ ] Review from the native team if needed.
- [ ] No breaking change or entry added to the changelog.
- [ ] No breaking change for hybrid SDKs or communicated to hybrid SDKs.
:crystal_ball: Next steps
While this might work in your fork, we don't intend to add attachments to the event payload. Attachments are a separate thing. They get sent via extra envelope items. What is your use case for this @izackp?
If you only want to attach an attachment to a single event, you can use the local scope as mentioned in the docs:
SentrySDK.captureMessage(message: "my message", block: { scope in
scope.addAttachment(fileAttachment)
})
I want attachments on crash reports. Exposing a property allows me to add logs/attachments in beforeSend very easily.
I looked at the proposed solution here and it doesn't seem to work: https://github.com/getsentry/sentry-cocoa/issues/1460#issuecomment-1085515472
I guess what you really want implemented are 'hints' which are also in the java version (I believe).. so I suppose this won't get accepted.
Exact usage:
options.beforeSend = { [weak self] (newEvent:Sentry.Event?) in
guard let myEvent = newEvent else { return nil }
if (myEvent.exceptions == nil && myEvent.error == nil) {
return myEvent
}
//if (myEvent.isAppHangEvent) { return myEvent; }
myEvent.attachments = self?.attachments().map({
return Sentry.Attachment(data: $0.data, filename: $0.fileName, contentType: $0.mimeType)
})
return myEvent
}
Yes, exactly. We need hints (https://github.com/getsentry/sentry-cocoa/issues/2325) for this. We don't want attachments to the event payload.
I'm closing this because, as mentioned here: https://github.com/getsentry/sentry-cocoa/pull/3896#issuecomment-2078810659, we will add hints at some point.