AWS Lambda

Sentry provides an integration with AWS Lambda ASP.NET Core Server through the Sentry.AspNetCore NuGet package.

Install

Add the Sentry dependency:

Copied
Install-Package Sentry.AspNetCore -Version 2.1.8

You can combine this integration with a logging library like log4net, NLog, or Serilog to include both request data as well as your logs as breadcrumbs. The logging ingrations also capture events when an error is logged.

Configuring

All ASP.NET Core configurations are valid here. But one configuration in particular is relevant.

FlushOnCompletedRequest ensures all events are flushed out. This is beacause the general ASP.NET Core hooks for when the process is exiting are not guaranteed to run in a serverless environment. This setting ensures that no event is lost if AWS recycles the process.

Copied

public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
    protected override void Init(IWebHostBuilder builder)
    {
        builder
            // Add Sentry
            .UseSentry(o =>
            {
              o.Dsn = "__PUBLIC_DSN__";
              // Required in Serverless environments
              o.FlushOnCompletedRequest = true;
            })
            .UseStartup<Startup>();
    }
}

Check out the Sentry ASP.NET Core documentation for the complete set of options.

Samples

You can edit this page on GitHub.