# applicationinsights-setup

Adopt this skill: https://proskills.md/skills/other/microsoft-applicationinsights-dotnet-skills-applicationinsights-setup

Page: https://proskills.md/skills/other/microsoft-applicationinsights-dotnet-skills-applicationinsights-setup
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: skills/applicationinsights-setup/SKILL.md
size: 8094
upstream: https://github.com/microsoft/applicationinsights-dotnet/blob/main/skills/applicationinsights-setup/SKILL.md

```text
---
name: applicationinsights-setup
description: >
  Sets up, migrates, or enhances Azure Monitor Application Insights in .NET
  applications. Detects application type and existing instrumentation
  automatically. Use when adding Application Insights, Azure Monitor,
  observability, or telemetry to ASP.NET Core, Worker Service, ASP.NET Classic,
  or Console apps, upgrading from Application Insights 2.x to 3.x, migrating
  from TelemetryClient to OpenTelemetry, or adding Entity Framework, Redis, SQL,
  or OTLP telemetry to apps already using Application Insights.
metadata:
  author: Microsoft
  version: 1.0.0
compatibility: Requires filesystem access to read .csproj files and source code. Works in GitHub Copilot, Cursor, Codex, Claude Code, Claude.ai with code execution, and any agent with file read capability.
---

# Application Insights Setup

This skill detects your .NET application type and instrumentation state, then guides you through the correct setup, migration, or enhancement path.

## Step 1 — Detect Application Type

Find all `.csproj` files (also `.fsproj`, `.vbproj`) in the workspace. If multiple non-library projects exist, ask the user which one to instrument before proceeding. Also check for `global.json` as a .NET workspace indicator.

First, check the `<Project Sdk="...">` attribute in the `.csproj`:

### SDK-style projects (modern format — has `Sdk` attribute)

| Signal | App Type |
|---|---|
| `Sdk="Microsoft.NET.Sdk.Web"` | **ASP.NET Core** |
| `Sdk="Microsoft.NET.Sdk.Worker"` | **Worker Service** |
| `Microsoft.Azure.Functions.Worker` or `Microsoft.NET.Sdk.Functions` in PackageReference | **Azure Functions** — not supported by this skill; refer to Azure Functions monitoring docs |
| `Sdk="Microsoft.NET.Sdk"` with `<OutputType>Exe</OutputType>` | **Console App** |
| `Sdk="Microsoft.NET.Sdk"` with `<OutputType>Library</OutputType>` or no OutputType | **Library** — does not get pipeline setup (no `AddApplicationInsightsTelemetry()` / `UseAzureMonitor()`), but may need **migration** if it uses `TelemetryClient`, `ITelemetryInitializer`, `ITelemetryProcessor`, or other 2.x APIs. Check for existing Application Insights package references and apply migration guidance if found. |

For ASP.NET Core / Worker Service, read `Program.cs` (or `Startup.cs` in older projects) to confirm hosting pattern:
- `WebApplication.CreateBuilder` → ASP.NET Core minimal APIs
- `Host.CreateDefaultBuilder` or `Host.CreateApplicationBuilder` → Generic Host
- `CreateWebHostBuilder` / `WebHost.CreateDefaultBuilder` → Legacy ASP.NET Core host

### Legacy projects (no `Sdk` attribute — old .csproj format)

If the `<Project>` element has no `Sdk` attribute, this is a legacy .NET Framework project. Detect the type using file and reference patterns:

| Signal (ANY ONE is sufficient) | App Type |
|---|---|
| `Web.config` with `<system.web>` section | **ASP.NET Classic** |
| `System.Web` in assembly references (`<Reference Include="System.Web" />`) | **ASP.NET Classic** |
| `Microsoft.AspNet.*` packages in `packages.config` | **ASP.NET Classic** |
| `.svc` files OR `System.ServiceModel` reference OR `[ServiceContract]` attributes | **WCF Service** — not supported by this skill; manual onboarding required |
| `Microsoft.Owin` or `Owin` in `packages.config`, or `IAppBuilder`/`IOwinContext` usage | **OWIN App** — not supported by this skill; manual onboarding required |
| `<OutputType>Exe</OutputType>` or `<OutputType>WinExe</OutputType>` with no web signals | **Console App** |

For ASP.NET Classic, further sub-type (all use the same setup):
- `Microsoft.AspNet.Mvc` package + `Controllers/` folder → **ASP.NET MVC**
- `.aspx` or `.ascx` files → **ASP.NET WebForms**
- Otherwise → **ASP.NET Classic (generic)**

**Entry point**: ASP.NET Classic uses `Global.asax.cs` as its entry point (not `Program.cs`).

## Step 2 — Detect Existing Instrumentation

Check multiple sources for evidence of existing instrumentation:

**Source 1 — Package references**: Scan `PackageReference` nodes in `.csproj` (check both `Version` and `VersionOverride` attributes for central package management). For legacy projects, scan `<package>` elements in `packages.config`. Version check: major version ≥ 3 → target version; handles wildcards (`3.*`), pre-release suffixes, and `v` prefix.

**Source 2 — Config files**: Check for `applicationinsights.config` (its presence indicates existing Classic SDK). Scan `appsettings*.json` for `InstrumentationKey` or `ApplicationInsights` sections.

**Detection priority** (if multiple types found): Application Insights SDK > plain OpenTelemetry.

| Package Found | Version | State |
|---|---|---|
| `Azure.Monitor.OpenTelemetry.AspNetCore` or `Azure.Monitor.OpenTelemetry.Exporter` | any | **Azure Monitor Distro** — not covered by this skill. This skill covers Application Insights 3.x SDK only. Inform the user and refer to Azure Monitor OpenTelemetry Distro documentation. |
| `Microsoft.ApplicationInsights.AspNetCore` | ≥ 3.0 | **Already on 3.x** → go to Enhancement |
| `Microsoft.ApplicationInsights.AspNetCore` | < 3.0 | **Brownfield 2.x** → go to Migration |
| `Microsoft.ApplicationInsights.WorkerService` | ≥ 3.0 | **Already on 3.x** → go to Enhancement |
| `Microsoft.ApplicationInsights.WorkerService` | < 3.0 | **Brownfield 2.x** → go to Migration |
| `Microsoft.ApplicationInsights.Web` | ≥ 3.0 | **Already on 3.x** → go to Enhancement |
| `Microsoft.ApplicationInsights.Web` | < 3.0 | **Brownfield 2.x** → go to Migration |
| `Microsoft.ApplicationInsights` (base only) | ≥ 3.0 | **Already on 3.x** → go to Enhancement |
| `Microsoft.ApplicationInsights` (base only) | < 3.0 | **Brownfield 2.x** → go to Migration (Console path) |
| `OpenTelemetry` / `OpenTelemetry.Api` / `OpenTelemetry.Extensions.Hosting` only (no AI SDK) | any | **OpenTelemetry only** → go to Enhancement (add Azure Monitor exporter) |
| None of the above, no `applicationinsights.config` | — | **Greenfield** → go to New Setup |

## Step 3 — Route to the Correct Guide

### Greenfield (No existing Application Insights)

Before making any code changes, read [references/opentelemetry-pipeline.md](references/opentelemetry-pipeline.md) to understand the architecture.

Then follow the guide for your app type (all greenfield paths use Application Insights 3.x SDK):
- **ASP.NET Core** → read [references/aspnetcore-greenfield.md](references/aspnetcore-greenfield.md)
- **Worker Service** → read [references/workerservice-greenfield.md](references/workerservice-greenfield.md)
- **ASP.NET Classic** → read [references/aspnet-classic-greenfield.md](references/aspnet-classic-greenfield.md)
- **Console App** → read [references/console-setup.md](references/console-setup.md)

### Migration (Application Insights 2.x → 3.x)

First, read [references/opentelemetry-pipeline.md](references/opentelemetry-pipeline.md) to understand how 3.x differs from 2.x.

Then scan the codebase using the template in [references/analysis-template.md](references/analysis-template.md). This identifies which migration guides are relevant.

Based on findings, read the applicable migration references:
- **All migrations**: start with [references/code-migration.md](references/code-migration.md) (property changes, removed APIs)
- **ITelemetryInitializer found** → [references/initializer-migration.md](references/initializer-migration.md)
- **ITelemetryProcessor found** → [references/processor-migration.md](references/processor-migration.md)
- **Custom sampling** → [references/sampling-migration.md](references/sampling-migration.md)
- **ILogger / logging config** → [references/ilogger-migration.md](references/ilogger-migration.md)
- **TelemetryClient breaking changes** → [references/telemetryclient-migration.md](references/telemetryclient-migration.md)
- **Dependency tracking config** → [references/dependency-tracking.md](references/dependency-tracking.md)
- **AAD / Token Credential authentication** → [references/aad-authentication-migration.md](references/
```
