AWS Lambda

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


Add the Sentry dependency:

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.


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.


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

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


You can edit this page on GitHub.