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

SentrySdk.CaptureException should add a breadcrumb for future exceptions

Open emrys90 opened this issue 1 year ago • 2 comments

Problem Statement

It appears that when you call SentrySdk.CaptureException, it does not add a breadrcrumb of itself, which means the next SentrySdk.CaptureException call does not show the previous exception in the dashboard. This seems like critical information to have by default, as its quite common for one exception to trigger another if things aren't handled well, and you will lose that contextual awareness that this exception was caused by a different exception happening.

Solution Brainstorm

No response

emrys90 avatar Jun 24 '24 01:06 emrys90

Ha, that's a super valid point! I never realized the SDK not doing that! Coming from the Unity SDK I just expected it to be there. The only instances I found where the Core SDK would add breadcrumbs itself were the BeforeSend and BeforeSendTransaction callbacks to let users know that it blew up: https://github.com/getsentry/sentry-dotnet/blob/5e54f086b1269f8251a9a388b1de38ee10779cb4/src/Sentry/SentryClient.cs#L208-L212 https://github.com/getsentry/sentry-dotnet/blob/5e54f086b1269f8251a9a388b1de38ee10779cb4/src/Sentry/SentryClient.cs#L443-L447

@bruno-garcia @jamescrosswell any thoughts on this? I can see this being an opt-in feature?

bitsandfoxes avatar Jun 24 '24 13:06 bitsandfoxes

We do this on the logging libraries. It makes sense to me, I think it was an oversight.

But take into account that we'd be double writing in the logging integrations, so we'd need to remove those.

https://github.com/getsentry/sentry-dotnet/blob/a11f10399e2e2258c211557cb7a9a6b4af84f94c/src/Sentry.Serilog/SentrySink.cs#L119

Would need a refactor. Or if we don't want to change the current behavior on the logging libraries, we could skip this new breadcrumb if the event was written by one of our logging libraries (by for example checkign against the sdk name)

bruno-garcia avatar Jun 24 '24 14:06 bruno-garcia

Either of the suggestions that bruno made sound good. Especially if it doesn't require/cause any user-facing changes (ie have the logging libraries do the right thing automatically)

ericsampson avatar Aug 30 '24 14:08 ericsampson

That would not even require being added in the next mayor.

bitsandfoxes avatar Aug 30 '24 15:08 bitsandfoxes

I think it's cleanest to do it once/always when capturing an exception and make sure the logging libraries either capture an exception or drop a breadcrumb (not both).

jamescrosswell avatar Aug 30 '24 22:08 jamescrosswell