sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Add the ability to attach on hard crash only

Open bruno-garcia opened this issue 4 years ago • 4 comments

Users have the use case of attaching files only when a hard crash happens (i.e: UncaughtExceptionHandler).

For example: User throws ParseException which has the path to a file that failed parsing. Currently there's no way to hook into processing that exception in a way that we can add that file as an attachment.

Request came from Discord.

bruno-garcia avatar May 07 '21 18:05 bruno-garcia

Is there any update on this? I still need it, but of course can look into alternative solutions if it's not going to be implemented. I am just not sure if I should wait or not.

Nohus avatar Sep 07 '21 19:09 Nohus

@Nohus we intend to work on it and it's in our backlog, but it's not prioritized yet.

marandaneto avatar Sep 08 '21 06:09 marandaneto

Suggestion for implementation that would have to be discussed with Client Infra TSC as this might be something all SDKs should do. If so the SDKs should do it in a similar manner.

Add a new method to EventProcessor that allows people to extract attachments from an exception. public List<Attachment> extractAttachments(SentryEvent event)

Default implementation could be added to return an empty list.

adinauer avatar Apr 28 '22 12:04 adinauer

@adinauer Should we move this issue to In progress and add to v6? or the hints improvements won't automatically fix this? Thanks.

marandaneto avatar May 11 '22 11:05 marandaneto

Closing as use case is supported by #2046

adinauer avatar Dec 28 '22 12:12 adinauer

Closing as use case is supported by #2046

:tada: Amazing. I just wish I knew it was possible since May. :smile:

Nohus avatar Dec 28 '22 15:12 Nohus

@Nohus sorry, forgot to update the issue after merging the PR(s). This test shows how you can add an attachment in beforeSend:

https://github.com/getsentry/sentry-java/blob/b3704c88d4b10a7c1cfbd922ba75811e484b6b8a/sentry/src/test/java/io/sentry/SentryClientTest.kt#L1724-L1728

adinauer avatar Dec 29 '22 05:12 adinauer