sentry-dotnet
sentry-dotnet copied to clipboard
Azure Function: SentrySDK Capture Exception does not send caught exception to Sentry.
Package
Sentry
.NET Flavor
.NET Core
.NET Version
3.1
OS
Windows
SDK Version
3.1
Self-Hosted Sentry Version
3.12
Steps to Reproduce
using (SentrySdk.Init())
{
try
{
var x = "x";
var y = double.Parse(x);
}
catch (Exception exception)
{
var ex = exception;
SentrySdk.CaptureException(ex);
await SentrySdk.FlushAsync(TimeSpan.FromSeconds(200));
throw;
}
}
- Created a simple Az Function
- This is working when the block of code inside try { ... } explicitly
throwsthe Exception. But with the sample code block, it does not send anything to Sentry.
Expected Result
Should appear in Sentry
Actual Result
Nothing -- unless explicitly thrown.
Hi. Thanks for raising this issue, as we certainly need to better document how to use Sentry with Azure Functions. There's been some discussion about this before - see #373.
You could try a few things:
- Initialize Sentry via dependency injection
- Use
FlushOnCompletedRequest = truein your Sentry options so you don't need to flush explicitly
That said, I understand there is probably still more work to do on our side to understand what we can and can't do with Azure Functions.
Please clarify a few things:
- Are you running the latest Sentry .NET SDK (currently 3.21.0), or an older version?
- Which nuget package did you use? (Sentry, Sentry.AspNetCore, Sentry.Extensions.Logging, etc.)
- Are you running ASP.Net Core in Azure Functions? Or just a plain function?
- Which functions runtime version and .NET version are you running, and is it in-process or out-of-process as shown on the chart here?
From your previous responses, I think you are on Azure Functions 3.x runtime, in-process, with .NET Core 3.1 and not using ASP.NET Core. Is that correct?
Thanks.
Hi. Closing this for now, and we'll work on better Azure Function support with #373.
Thanks.