AWS Lambda

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

Add the Sentry dependency:

Copied
Install-Package Sentry.AspNetCore -Version 4.2.1

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 because 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 = "https://examplePublicKey@o0.ingest.sentry.io/0";
                // When configuring for the first time, to see what the SDK is doing:
                o.Debug = true;
                // Set TracesSampleRate to 1.0 to capture 100%
                // of transactions for performance monitoring.
                // We recommend adjusting this value in production
                o.TracesSampleRate = 1.0;
                // Required in Serverless environments
                o.FlushOnCompletedRequest = true;
            })
            .UseStartup<Startup>();
    }
}

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

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").