Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Attachments in beforeSend #1460

Open
philipphofmann opened this issue Nov 17, 2021 · 5 comments
Open

feat: Add Attachments in beforeSend #1460

philipphofmann opened this issue Nov 17, 2021 · 5 comments

Comments

@philipphofmann
Copy link
Member

Currently, adding attachments in beforeSend is not possible, because the Cocoa SDK doesn't have hints as for example, Python does. Either we add hints or the SDK should offer another way of adding attachments in beforeSend. Furthermore, it would be nice to also drop attachments in beforeSend.

This came up in #1459. A user wants to add an attachment to an OOM event.

@philipphofmann
Copy link
Member Author

Hints could be its own class extending a dictionary with methods for adding an attachment. Before implementing this we still need to investigate the use cases of hints in the Cocoa SDK. Look at Python and Android.

How this could look like with hints:

SentrySDK.start { options in
    options.beforeSend { event, hint in
       hint.addAttachment(Attachment())
       hint.removeAttachment()
       hint.attachments
    }
}

@philipphofmann philipphofmann moved this from Needs Discussion to Needs Investigation in Mobile & Cross Platform SDK Nov 24, 2021
@philipphofmann philipphofmann moved this from Needs Investigation to Backlog in Mobile & Cross Platform SDK Dec 15, 2021
@eric
Copy link

eric commented Mar 31, 2022

How can we add attachments to any sort of crashes at all? We have logs that would be helpful in identifying why a crash happened and can't figure out how to send it.

@philipphofmann
Copy link
Member Author

@eric, sadly that is currently not possible. We could add an API for capturing attachemts; then you could do

SentrySDK.start { options in
    // ...
    
    options.onCrashedLastRun = { event in
        SentrySDK.captureAttachment(...)
    }
}

But I think the proper way would be adding hints to the SDK, so you can do this in beforeSend.

@tmm1
Copy link
Contributor

tmm1 commented Mar 31, 2022

What if we use the following existing api, what is the expected behavior?

  [SentrySDK configureScope:^(SentryScope * _Nonnull scope) {
    [scope addAttachment:...];
  }];

@philipphofmann
Copy link
Member Author

philipphofmann commented Apr 1, 2022

@tmm1, your approach could work, but SentrySDK.start installs the SentryCrashIntegration, which then, on a background thread, will send the crash report. So it could work in most cases, but there is no guarantee. So you could do

SentrySDK.start { options in
    // ...
    
    options.onCrashedLastRun = { event in
        SentrySDK.configureScope { scope in
            scope.clearAttachments()
        }
    }
}

SentrySDK.configureScope { scope in
    scope.addAttachment(...)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

5 participants