Azure Functions

Learn about Sentry's .NET integration with Azure Functions.

Sentry provides an integration with Azure Functions through the Sentry.Azure.Functions.Worker NuGet package. All triggers are supported.

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 dependency to your Azure Functions application:

Copied
dotnet add package Sentry.Azure.Functions.Worker -v 4.12.1

This package extends Sentry.Extensions.Logging. This means that besides the Azure Functions related features, through this package you'll also get access to the ILogger<T> integration and also the features available in the main Sentry SDK.

Sentry integration with Azure Functions is done by calling .UseSentry() and specifying the options, for example:

If using the ASP.NET Core integration add UseSentry to the ConfigureFunctionsWebApplication call instead.

Copied
using Sentry.Azure.Functions.Worker;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults((host, builder) =>
    {
        builder.UseSentry(host, options =>
        {
            options.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/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();

This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.

Copied
using Sentry;

try
{
    throw null;
}
catch (Exception ex)
{
    SentrySdk.CaptureException(ex);
}

Help improve this content
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").