AWS Lambda
Learn about Sentry's .NET integration with AWS Lambda and ASP.NET Core.
Sentry provides an integration with AWS Lambda ASP.NET Core Server through the Sentry.AspNetCore NuGet package.
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:
Install-Package Sentry.AspNetCore -Version 4.12.0
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.
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{
protected override void Init(IWebHostBuilder builder)
{
builder
// Add Sentry
.UseSentry(options =>
{
options.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 tracing.
// We recommend adjusting this value in production
o.TracesSampleRate = 1.0;
// Required in Serverless environments
options.FlushOnCompletedRequest = true;
})
.UseStartup<Startup>();
}
}
Check out the Sentry ASP.NET Core documentation for the complete set of options.
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
using Sentry;
try
{
throw null;
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
}
- Our samples on GitHub demonstrate Sentry on AWS Lambda. (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").