Snapshot Debugging in Azure
Posted: (EET/GMT+2)
Azure App Service and Application Insights include a new feature called Snapshot Debugging. When an unhandled exception occurs, Azure can capture a full snapshot of the app state: the local variables, call stack, and even object contents, all without stopping your app.
To enable it, install the Snapshot Debugger site extension (in Azure) or the NuGet package (in code):
Install-Package Microsoft.ApplicationInsights.SnapshotCollector
Then, configure the package it in your Startup.cs:
using Microsoft.ApplicationInsights.SnapshotCollector;
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
services.AddSnapshotCollector(configuration =>
{
configuration.IsEnabledInDeveloperMode = false;
});
}
When an exception occurs in production, the snapshot is collected and uploaded to Application Insights. You can open it directly in Visual Studio Enterprise and inspect everything as if you had paused the debugger at that moment.
This is a great way to fix elusive bugs that only appear in production. It gives you visibility without attaching a live debugger or reproducing the issue manually.