Azure Functions
Learn about Sentry's .NET integration with Azure Functions.
Sentry provides an integration with Azure Functions through the Sentry.Extensions.Logging and Sentry.OpenTelemetry NuGet packages.
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
Add the Sentry dependencies to your Azure Functions application:
dotnet add package Sentry.Extensions.Logging -v 5.16.2
// ___PRODUCT_OPTION_START___ performance
dotnet add package Sentry.OpenTelemetry -v 5.16.2
dotnet add package OpenTelemetry
dotnet add package OpenTelemetry.Extensions.Hosting
dotnet add package OpenTelemetry.Instrumentation.Http
// ___PRODUCT_OPTION_END___
The Sentry.Extensions.Logging package also provides access to the ILogger<T> integration and the other core features available in the Sentry SDK.
The core features of Sentry are enabled by calling AddSentry when configuring logging.
Performance tracing can be enabled by adding Sentry to the OpenTelemetry TracerProviderBuilder and then configuring Sentry itself to use OpenTelemetry.
For example:
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OpenTelemetry;
// ___PRODUCT_OPTION_START___ performance
using OpenTelemetry.Trace;
// ___PRODUCT_OPTION_END___
using Sentry.OpenTelemetry;
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
// ___PRODUCT_OPTION_START___ performance
.ConfigureServices(services =>
{
services.AddOpenTelemetry().WithTracing(builder =>
{
builder
.AddSentry() // <-- Configure OpenTelemetry to send traces to Sentry
.AddHttpClientInstrumentation(); // From OpenTelemetry.Instrumentation.Http, instruments outgoing HTTP requests
});
})
// ___PRODUCT_OPTION_END___
.ConfigureLogging(logging =>
{
logging.AddSentry(options =>
{
options.Dsn = "___PUBLIC_DSN___";
// ___PRODUCT_OPTION_START___ performance
options.TracesSampleRate = 1.0;
options.UseOpenTelemetry(); // <-- Configure Sentry to use open telemetry
options.DisableSentryHttpMessageHandler = true; // So Sentry doesn't also create spans for outbound HTTP requests
// ___PRODUCT_OPTION_END___
options.Debug = true;
});
})
.Build();
await host.RunAsync();
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
try
{
throw null;
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
- Azure Functions Sample demonstrates Sentry with Azure Functions Isolated Worker SDK. (C#)
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").