Sentry documentation only mentions the AspNetCore version
https://sentry.io/getcodepl/aspnet-core/getting-started/dotnet-aspnetcore/
Solution depends on Azure function type. In-process or isolated
Due to changes in Microsoft Azure SDK, version of Sentry.AspNetCore doesn't fit with the new Azure Function builder approach. But there is a workaround:
Install-Package Sentry.AspNetCore -Version 4.13.0
Program.cs
using Sentry.Azure.Functions.Worker;
...
//NOTE: WORKAROUND
var context = new HostBuilderContext(new Dictionary<object, object>())
{
Configuration = builder.Configuration,
};
builder.UseSentry(context, options =>
{
options.Dsn = "https://[email protected]/0";
// When configuring for the first time, to see what the SDK is doing:
options.Debug = true;
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
});
It should be fixed in Sentry.AspNetCore 5.x version.
Base on: https://github.com/getsentry/sentry-dotnet/issues/3773
Install-Package Sentry.AspNetCore -Version 4.13.0
Program.cs
using Sentry.Azure.Functions.Worker;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults((host, builder) =>
{
builder.UseSentry(host, options =>
{
options.Dsn = "https://[email protected]/0";
// When configuring for the first time, to see what the SDK is doing:
options.Debug = true;
// Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
// We recommend adjusting this value in production.
options.TracesSampleRate = 1.0;
});
})
.Build();
await host.RunAsync();
Source
Install-Package Sentry.AspNetCore
[FunctionName("Function1")]
public static async Task RunAsync([TimerTrigger("0 */5 * * * *", RunOnStartup = true)] TimerInfo myTimer, ILogger log)
{
using (SentrySdk.Init())
{
try
{
//Code
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
throw; //if you want to pass it into Azure
}
}
}
local.settings.json
"Values": {
"SENTRY_DSN": "https://your-dsn-url.ingest.sentry.io/xxx"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With