Introduction
Application performance monitoring is critical for maintaining healthy production systems, but manually managing monitoring resources through the Azure portal becomes tedious at scale. The Azure Application Insights management SDK for .NET solves this by enabling programmatic control over your entire observability infrastructure—from creating Application Insights components to configuring availability tests and building custom workbooks.
This skill empowers AI agents to automate monitoring setup, respond to performance issues by adjusting configurations, and maintain consistent observability across environments without manual intervention.
What This Skill Does
The azure-mgmt-applicationinsights-dotnet skill provides comprehensive control over Azure Application Insights resources through the Azure Resource Manager API. It handles the complete lifecycle of application performance monitoring infrastructure, including component creation, availability testing, API key management, and custom dashboard development.
Key capabilities include:
- Component Management: Create workspace-based Application Insights instances with custom retention policies and sampling configurations
- Availability Testing: Set up URL ping tests and multi-step web tests from multiple global locations
- API Access Control: Generate and manage API keys for programmatic telemetry access
- Workbook Creation: Build custom analysis dashboards using Kusto Query Language
- Storage Integration: Link storage accounts for long-term data export and Service Profiler
- Configuration Updates: Modify retention periods, sampling rates, and network access policies
Getting Started
Installation is straightforward via NuGet package manager. You'll need both the management SDK and Azure Identity library for authentication:
dotnet add package Azure.ResourceManager.ApplicationInsights
dotnet add package Azure.Identity
Authentication uses Azure's DefaultAzureCredential, which automatically tries multiple authentication methods in sequence—ideal for code that runs both locally (using Azure CLI credentials) and in production (using managed identities):
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.ApplicationInsights;
ArmClient client = new ArmClient(new DefaultAzureCredential());
Before creating resources, you'll need an existing Azure subscription and resource group. The SDK supports environment variables for common identifiers:
export AZURE_SUBSCRIPTION_ID=<your-subscription-id>
export AZURE_RESOURCE_GROUP=<your-resource-group>
Key Features
Workspace-Based Components
Modern Application Insights deployments should use workspace-based architecture, which stores telemetry in a Log Analytics workspace for enhanced querying and cost management:
ApplicationInsightsComponentData data = new ApplicationInsightsComponentData(
AzureLocation.EastUS,
ApplicationInsightsApplicationType.Web)
{
Kind = "web",
WorkspaceResourceId = new ResourceIdentifier(workspaceId),
IngestionMode = IngestionMode.LogAnalytics,
RetentionInDays = 90,
SamplingPercentage = 100
};
ArmOperation<ApplicationInsightsComponentResource> operation = await components
.CreateOrUpdateAsync(WaitUntil.Completed, "my-appinsights", data);
Multi-Location Availability Tests
Web tests check application availability from multiple Azure regions, providing global health monitoring:
WebTestData urlPingTest = new WebTestData(AzureLocation.EastUS)
{
WebTestKind = WebTestKind.Ping,
Frequency = 300, // Check every 5 minutes
Timeout = 120,
Locations =
{
new WebTestGeolocation { WebTestLocationId = "us-ca-sjc-azr" },
new WebTestGeolocation { WebTestLocationId = "emea-gb-db3-azr" },
new WebTestGeolocation { WebTestLocationId = "apac-sg-sin-azr" }
}
};
API Key Generation
API keys enable programmatic access to telemetry data without requiring Azure authentication:
ApplicationInsightsApiKeyContent keyContent = new ApplicationInsightsApiKeyContent
{
Name = "ReadTelemetryKey",
LinkedReadProperties = { componentApiPath, componentAgentConfigPath }
};
ApplicationInsightsComponentApiKeyResource apiKey = await apiKeys
.CreateOrUpdateAsync(WaitUntil.Completed, keyContent);
The API key is only shown once during creation—store it securely immediately.
Usage Examples
Automated Environment Setup: When deploying a new application environment (staging, production), automatically provision Application Insights with standardized configurations:
// Create App Insights for each environment with consistent settings
foreach (var env in new[] { "dev", "staging", "prod" })
{
var retentionDays = env == "prod" ? 180 : 90;
var samplingRate = env == "prod" ? 50 : 100;
await CreateAppInsightsComponent($"myapp-{env}", retentionDays, samplingRate);
}
Health Check Automation: Automatically create availability tests for all critical endpoints when a service is deployed:
// After service deployment, register health check
await CreateWebTest(
testName: $"health-check-{serviceName}",
url: $"https://{serviceName}.azurewebsites.net/health",
locations: globalLocations
);
Dynamic Dashboard Creation: Generate workbooks programmatically based on application architecture:
// Create custom workbook for service-specific metrics
string kqlQuery = $@"
requests
| where cloud_RoleName == '{serviceName}'
| summarize count() by bin(timestamp, 5m)
| render timechart
";
await CreateWorkbook($"{serviceName}-dashboard", kqlQuery);
Best Practices
Use Workspace-Based Deployments: Always link Application Insights to a Log Analytics workspace rather than using standalone instances. This enables advanced querying, longer retention at lower cost, and integration with other Azure Monitor features.
Implement Appropriate Sampling: For high-volume applications, configure sampling to reduce costs while maintaining statistical accuracy. Start with 100% in development, 50% in production, and adjust based on telemetry volume.
Secure Connection Strings: Never hardcode connection strings or instrumentation keys. Store them in Azure Key Vault and reference them using managed identities.
Tag Resources Comprehensively: Apply consistent tags for environment, application, owner, and cost center to enable accurate tracking and cost allocation.
Monitor Multiple Locations: Configure availability tests from at least three geographically distributed locations to distinguish between regional outages and global issues.
Set Realistic Retention: Balance compliance requirements against cost. Ninety days is often sufficient for production troubleshooting; longer retention should be justified by specific regulatory or business needs.
When to Use This Skill
Use this skill when you need to:
- Provision Application Insights components as part of infrastructure-as-code deployments
- Automate availability test creation for new services or endpoints
- Generate API keys for integration with external monitoring systems
- Create custom workbooks programmatically based on application structure
- Standardize observability configurations across multiple environments
- Manage retention policies and sampling rates based on changing requirements
- You need to send telemetry data from applications (use Application Insights SDK instead)
- You want to query telemetry data (use Azure Monitor Query SDK)
- You're managing alerts and action groups (use Azure Monitor management SDK)
- Simple Azure portal configuration would suffice for one-time setup
Related Skills
- azure-mgmt-applicationinsights-dotnet - This skill
- azure-monitor-query-py - Query Application Insights telemetry data
- azure-monitor-ingestion-py - Send custom telemetry to Azure Monitor
- azure-monitor-opentelemetry-exporter-py - Export OpenTelemetry data to Application Insights
Source
This skill is built on Microsoft's official Azure SDK for .NET. The source code, examples, and detailed API documentation are available in the Azure SDK for .NET repository.
For comprehensive service documentation, including portal-based management and telemetry SDK usage, visit the Application Insights overview.