CaptureException not showing up in sentry (C#)


#1

I’m using the Sentry SDK for C# release 1.1.2 and having some trouble. I am a new user so please excuse my ignorance if this easy!

I have set up a simple integration with my C# .NET web app to capture exceptions using Sentry. I am testing by having an error in my code, and can debug through my web app to see that the SentrySdk.CaptureException() method is being called. But the exception never shows up in the sentrio.io dashboard for the project.

Here is the relevant code:
Set up:
using (SentrySdk.Init(o => { o.Dsn = new Dsn("https://ZZZ@sentry.io/ZZZ"); o.Environment = "dev"; o.SendDefaultPii = true; o.Debug = true; } )) { }

Error logging:
SentrySdk.CaptureException(ex);

What am I missing?


#2

One common issue with this scenario (I’ve hit that) is when debugging line by line and stopping the debugger, the app is terminated immediately. That means that stuff like finalizers don’t run and the code doesn’t continue execution to call Dispose in the disposable returned by Init.

Other than that I’m not sure what could be going wrong. If you let the code pass outside the using block so that the SDK can flush pending events queued up, it should show up in Sentry properly.

Please make sure the SDK should be initialized only once. So the Init call should be on Global.asax.cs in case of ASP.NET or use the package Sentry.AspNetCore if you are using ASP.NET Core.

This repo has samples for both cases:

Non web samples and more can be found here:

I hope this helps. Let me know otherwise.


#3

Thanks for your help. Using the sentry-dotnet-samples and your note about the Global asax led me to the realization that I needed to persist the result of the SentrySdk.Init() call instead of doing the using() statement. Once I did that, the data started flowing to the sentry.io dashboard.