microsoft/enable-profiler
Guide users through enabling the Application Insights Profiler for .NET on their platform. Use this when asked to enable the profiler, set up profiling, or when profiler data is missing.
npx skills add https://github.com/microsoft/code-optimizations-skills --skill enable-profiler
When asked to enable the Application Insights Profiler for .NET, or when another skill (e.g., perf-optimization) determines that no profiler data exists, follow these steps:
investigation-notes.md with the confirmed values. If only a resource ID is available, resolve the app ID using resolve-app-id.md.ServiceProfilerIndex (session-level) and ServiceProfilerSample (request-level) events.ServiceProfilerIndex events exist (no ServiceProfilerSample) → the profiler IS running but is not capturing request-level samples. Apply the shared-resource caveat below first — if the index events belong to a different cloud_RoleName, treat the profiler as NOT enabled for this app and proceed to step 4. If the events do belong to the target app, this is typically a traffic or trigger issue, not an enablement issue. Inform the user the profiler is enabled, and suggest checking traffic volume and trigger thresholds rather than re-enabling.> ⚠️ Shared-resource caveat — avoid false positives. A single Application Insights resource can receive telemetry from multiple apps / cloud roles. If the App ID was *inferred* (e.g., read from a connection string in local.settings.json or appsettings.json) rather than explicitly confirmed by the user, profiler events on that resource may belong to a different app. Before concluding "already enabled", break the events down by cloud_RoleName (the status script does this) and confirm with the user that the role producing profiler data is the app you are enabling. If it is a different role — or the target role shows zero profiler events — treat the profiler as NOT enabled for this app and proceed to step 4.
4a. Check for profiler NuGet packages and code:
*.csproj files for profiler NuGet references:Microsoft.ApplicationInsights.Profiler.AspNetCore (classic SDK / EventPipe)Azure.Monitor.OpenTelemetry.Profiler (OpenTelemetry / EventPipe)Program.cs or Startup.cs for profiler registration calls:AddServiceProfiler (classic SDK)AddAzureMonitorProfiler (OpenTelemetry)4b. If profiler code IS present — run connection string match check:
The profiler is configured in code but producing no events on the target resource. A common cause is a connection string mismatch — the app may be sending data to a different App Insights resource. Run check-connection-string-match.md to compare the app's configured connection string against the target resource.
check-connection-string-match.md). Note that connection strings are often overridden at deployment time, so a source-code mismatch does not necessarily mean the app is sending data elsewhere. Ask the user to confirm which scenario applies before deciding next steps. Do not proceed with enablement steps until the mismatch is resolved or confirmed as a non-issue.4c. Infer environment from source code:
When source code is available, attempt to infer the answers to the environment questions below before asking them. This avoids redundant questions when the answers are already visible:
<TargetFramework> in *.csproj — values like net6.0, net8.0, net9.0, net10.0 indicate .NET (modern); net48, net472 indicate .NET Framework.*.bicep or ARM template files — look for kind: 'linux' vs kind: 'app', Microsoft.Web/sites (App Service), Microsoft.ContainerInstance (ACI), Microsoft.App/containerApps (Container Apps). Also detect Azure Functions from the project itself: an <AzureFunctionsVersion> property or Microsoft.Azure.Functions.Worker package in *.csproj, a host.json file, or FUNCTIONS_WORKER_RUNTIME in local.settings.json. A value of dotnet-isolated means the isolated worker model (the profiler runs in your worker process), versus dotnet for the in-process model.*.csproj for the App Insights / OpenTelemetry packages:Azure.Monitor.OpenTelemetry.AspNetCore → OTel distro (UseAzureMonitor()).Azure.Monitor.OpenTelemetry.Exporter (often with Microsoft.Azure.Functions.Worker.OpenTelemetry and ConfigureFunctionsWorkerDefaults()) → OTel exporter path, common in Azure Functions isolated worker apps. host.json with "telemetryMode": "OpenTelemetry" is another strong OTel signal. Both OTel paths use the EventPipe profiler via Azure.Monitor.OpenTelemetry.Profiler / AddAzureMonitorProfiler().Microsoft.ApplicationInsights.AspNetCore → classic SDK (version 2.x uses AddServiceProfiler(); version 3.x is OTel-based and uses AddAzureMonitorProfiler() — check the major version to select the correct profiler package).local.settings.json (APPLICATIONINSIGHTS_CONNECTION_STRING) for Functions apps, in addition to appsettings*.json. Note the ApplicationId GUID embedded in a connection string is the App Insights App ID — but treat it as *inferred* (see the shared-resource caveat in step 3) until the user confirms it is this app's resource.If all three answers can be inferred, present them to the user for confirmation and skip the corresponding questions in step 5. If any are ambiguous, ask only the questions that couldn't be inferred.
4d. If profiler code is NOT present → proceed to step 5 to determine the environment and provide full enablement instructions.
Question 1 (if runtime not inferred): What .NET runtime does your application target?
.NET (modern) — .NET 6, .NET 8, or later.NET Framework — .NET Framework 4.xQuestion 2 (if hosting not inferred): Where is your application hosted?
Question 2b (if Azure Functions selected and worker model not inferred): Which Azure Functions worker model are you using?
FUNCTIONS_WORKER_RUNTIME = dotnet)FUNCTIONS_WORKER_RUNTIME = dotnet-isolated)> This determines the profiler agent: in-process uses ETW (no code change), isolated worker uses EventPipe (code change required). If the user is unsure, check local.settings.json or the Azure portal Function App configuration for FUNCTIONS_WORKER_RUNTIME.
Question 3 (if SDK not inferred, and .NET modern with EventPipe applicable): Which Application Insights SDK are you using?
Azure.Monitor.OpenTelemetry.AspNetCore)Microsoft.ApplicationInsights.AspNetCore)First, determine the correct agent using the selection guide. Fetch online first, fall back to local:
web_fetch with URL https://github.com/Azure/azuremonitor-opentelemetry-profiler-net/blob/main/docs/ProfilerAgentSelectionGuide.md and max_length: 5000Apply the decision tree:
| .NET Runtime | Hosting | Profiler Agent | Code Change Required? |
|---|---|---|---|
| .NET Framework | Any Windows Azure service | ETW | No |
| .NET (modern) | App Service (Windows) | ETW (simplest) or EventPipe | No for ETW; Yes for EventPipe |
| .NET (modern) | App Service (Linux) | EventPipe | Yes |
| .NET (modern) | Containers (AKS, Container Apps, ACI) | EventPipe | Yes |
| .NET (modern) | Azure Functions — in-process (classic AI SDK), App Service plan | ETW | No |
| .NET (modern) | Azure Functions — isolated worker and/or OpenTelemetry | EventPipe | Yes |
| .NET (modern) | VMs / VMSS | ETW or EventPipe | No for ETW; Yes for EventPipe |
| .NET (modern) | Service Fabric | ETW | No |
> ⚠️ Do NOT use both ETW and EventPipe at the same time — the combined overhead is not recommended.
> Azure Functions note. The ETW (no-code) Functions profiler attaches to the classic in-process Application Insights pipeline. An isolated-worker Functions app — especially one configured for OpenTelemetry (telemetryMode: OpenTelemetry, Azure.Monitor.OpenTelemetry.Exporter) — does not use that pipeline, so ETW may not produce profiler data for the worker process. In this case, use the EventPipe profiler in code: add Azure.Monitor.OpenTelemetry.Profiler and chain .AddAzureMonitorProfiler() onto the Functions OTel builder (e.g. AddOpenTelemetry().UseFunctionsWorkerDefaults().UseAzureMonitorExporter().AddAzureMonitorProfiler()). The profiler reads the connection string from APPLICATIONINSIGHTS_CONNECTION_STRING, so no extra wiring is needed when that is already set.
Based on the selected agent and platform, fetch only the one relevant page. Use max_length: 5000 for all web_fetch calls:
| Agent | Platform | Online URL | Local fallback |
|---|---|---|---|
| ETW | App Service (Windows) | https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler | enablement-overview.md |
| ETW | Azure Functions | https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-azure-functions | enablement-overview.md |
| ETW | VMs / VMSS | https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-vm | enablement-overview.md |
| ETW | Service Fabric | https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-servicefabric | enablement-overview.md |
| EventPipe | App Service (Linux) | https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-aspnetcore-linux | enablement-overview.md |
| EventPipe | Containers | https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-containers | enablement-overview.md |
| EventPipe | Azure Functions (isolated) | Use local reference directly (not yet documented upstream) | enablement-overview.md |
| EventPipe | Any (OTel SDK) | https://github.com/Azure/azuremonitor-opentelemetry-profiler-net | enablement-overview.md |
Present the enablement instructions to the user in a clear, step-by-step format. Include:
> Tip — Copilot-based enablement: For EventPipe with the OTel SDK, the user can alternatively use a Copilot prompt file to enable the profiler automatically. See: https://github.com/Azure/azuremonitor-opentelemetry-profiler-net/blob/main/docs/AddAzureMonitorProfilerWithCoPilot.md
ServiceProfilerIndex and ServiceProfilerSample events are found → apply the shared-resource caveat from step 3: confirm the events' cloud_RoleName belongs to the target app before declaring success. If confirmed, the profiler is capturing request-level data — full success.ServiceProfilerIndex events appear → confirm cloud_RoleName matches the target app. If it does, the profiler is running sessions but not capturing individual requests. This is normal if traffic is low — suggest the user generate more traffic and wait for the next profiling window. If the events belong to a different role, treat as not yet producing data for this app.Microsoft.ServiceProfiler and Microsoft.ApplicationInsights.Profiler to DebugOnce both event types are confirmed, suggest the user re-run the perf-optimization skill to investigate performance issues with the now-available profiler data. For distributed systems with multiple services, also suggest running discover-related-resources.md to map all related App Insights resources before starting analysis — this ensures profiler data and telemetry from downstream components are included in the investigation.
Take microsoft/enable-profiler from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.