agentleFS
MicrosoftKnown publishermicrosoft/code-optimizations-skills/skills/enable-profiler/SKILL.md

enable-profiler

Skill5 starsChanged 5 months agoMITView on GitHub

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.

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. About 0 are common, 12 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈12

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When asked to enable the Application Insights Profiler for .NET, or when another skill (e.g., perf-optimization) determines that no …

    line 9
  2. Distinctive:

    If both event types are found → the profiler is already enabled and capturing request data — confirm the data belongs to the target app …

    line 16
  3. Distinctive:

    If neither event type is found → the profiler is not enabled.

    line 18
  4. Very specific:

    Search *.csproj files for profiler NuGet references:

    line 25
  5. Very specific:

    Search Program.cs or Startup.cs for profiler registration calls:

    line 28
  6. Distinctive:

    If connection strings match → the profiler is configured and pointing to the correct resource, but not producing data for another reason.

    line 35
  7. Distinctive:

    When source code is available, attempt to infer the answers to the environment questions below before asking them.

    line 39
  8. Very specific:

    Runtime: Check <TargetFramework> in *.csproj — values like net6.0, net8.0, net9.0, net10.0 indicate .NET (modern).

    line 40
  9. Very specific:

    SDK: Check *.csproj for the App Insights / OpenTelemetry packages:

    line 42
  10. Distinctive:

    If all three answers can be inferred, present them to the user for confirmation and skip the corresponding questions in step 5.

    line 48
  11. Distinctive:

    Not sure / not set up yet

    line 77
  12. Distinctive:

    If fetch fails: read profiler-agent-selection-guide.md

    line 85
  13. Very specific:

    If both ServiceProfilerIndex and ServiceProfilerSample events are found → apply the shared-resource caveat from step 3: confirm the events' …

    line 129
  14. Distinctive:

    If no events appear after the expected wait time, suggest troubleshooting:

    line 131
  15. Distinctive:

    Verify the connection string is correct

    line 132
  16. Distinctive:

    Check the application logs for profiler startup messages

    line 133
  17. Distinctive:

    Ensure there is traffic hitting the application

    line 134
  18. Distinctive:

    Only one profiler can be attached per web app

    line 143

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Enable Application Insights 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:

  1. Check investigation notes and gather inputs — Follow the Standard Skill Preamble to check for existing investigation context and gather inputs.
  2. Identify the Application Insights resource — If the investigation notes didn't have the resource or the user wants a different one, follow the steps in the Standard Skill Preamble. After the resource is confirmed, write or update investigation-notes.md with the confirmed values. If only a resource ID is available, resolve the app ID using resolve-app-id.md.
  3. Check if the profiler is already active — Run the script in check-profiler-status.md to query for both ServiceProfilerIndex (session-level) and ServiceProfilerSample (request-level) events.

    • If both event types are found → the profiler is already enabled and capturing request data — confirm the data belongs to the target app before concluding (see the caveat below), then inform the user and stop.
    • If only 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.
    • If neither event type is found → the profiler is not enabled. Proceed to step 4.

    ⚠️ 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.

  4. Check local source code for existing profiler configuration — Before asking the user environment questions, inspect the source code in the working directory to determine whether the profiler is already configured in code and whether the connection string matches the target resource.

    4a. Check for profiler NuGet packages and code:

    • Search *.csproj files for profiler NuGet references:
      • Microsoft.ApplicationInsights.Profiler.AspNetCore (classic SDK / EventPipe)
      • Azure.Monitor.OpenTelemetry.Profiler (OpenTelemetry / EventPipe)
    • Search 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.

    • If a mismatch is detected → present it to the user as a possible explanation (see the troubleshooting guidance in 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.
    • If connection strings match → the profiler is configured and pointing to the correct resource, but not producing data for another reason. Continue to step 5.
    • If no connection strings are found locally → the app's connection string may be set via environment variables, App Service configuration, or CI/CD at deployment time. Cannot verify from source code alone. Continue to step 5 and consider asking the user how the connection string is configured.

    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:

    • Runtime: Check <TargetFramework> in *.csproj — values like net6.0, net8.0, net9.0, net10.0 indicate .NET (modern); net48, net472 indicate .NET Framework.
    • Hosting: Check for *.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.
    • SDK: Check *.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).
    • Connection string source: also look in 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.

  5. Determine the user's environment — Ask the user any questions not already answered by source code inspection in step 4 (use multiple-choice where possible):

    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.x

    Question 2 (if hosting not inferred): Where is your application hosted?

    • Azure App Service (Windows)
    • Azure App Service (Linux)
    • Containers (AKS, Container Apps, Container Instances)
    • Azure Functions (App Service plan)
    • Azure Virtual Machines or Virtual Machine Scale Sets
    • Azure Service Fabric
    • Other / not sure

    Question 2b (if Azure Functions selected and worker model not inferred): Which Azure Functions worker model are you using?

    • In-process (FUNCTIONS_WORKER_RUNTIME = dotnet)
    • Isolated worker (FUNCTIONS_WORKER_RUNTIME = dotnet-isolated)
    • Not sure

    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 distribution (Azure.Monitor.OpenTelemetry.AspNetCore)
    • Classic Application Insights SDK (Microsoft.ApplicationInsights.AspNetCore)
    • Not sure / not set up yet
  6. Select the profiler agent and provide enablement instructions — Based on the user's answers (or inferred values from step 4), determine the correct profiler agent and fetch the relevant enablement documentation.

    Selecting the profiler agent

    First, determine the correct agent using the selection guide. Fetch online first, fall back to local:

    • Try: web_fetch with URL https://github.com/Azure/azuremonitor-opentelemetry-profiler-net/blob/main/docs/ProfilerAgentSelectionGuide.md and max_length: 5000
    • If fetch fails: read profiler-agent-selection-guide.md

    Apply the decision tree:

    .NET RuntimeHostingProfiler AgentCode Change Required?
    .NET FrameworkAny Windows Azure serviceETWNo
    .NET (modern)App Service (Windows)ETW (simplest) or EventPipeNo for ETW; Yes for EventPipe
    .NET (modern)App Service (Linux)EventPipeYes
    .NET (modern)Containers (AKS, Container Apps, ACI)EventPipeYes
    .NET (modern)Azure Functions — in-process (classic AI SDK), App Service planETWNo
    .NET (modern)Azure Functions — isolated worker and/or OpenTelemetryEventPipeYes
    .NET (modern)VMs / VMSSETW or EventPipeNo for ETW; Yes for EventPipe
    .NET (modern)Service FabricETWNo

    ⚠️ 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.

    Fetching enablement instructions

    Based on the selected agent and platform, fetch only the one relevant page. Use max_length: 5000 for all web_fetch calls:

    AgentPlatformOnline URLLocal fallback
    ETWApp Service (Windows)https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profilerenablement-overview.md
    ETWAzure Functionshttps://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-azure-functionsenablement-overview.md
    ETWVMs / VMSShttps://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-vmenablement-overview.md
    ETWService Fabrichttps://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-servicefabricenablement-overview.md
    EventPipeApp Service (Linux)https://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-aspnetcore-linuxenablement-overview.md
    EventPipeContainershttps://learn.microsoft.com/en-us/azure/azure-monitor/profiler/profiler-containersenablement-overview.md
    EventPipeAzure Functions (isolated)Use local reference directly (not yet documented upstream)enablement-overview.md
    EventPipeAny (OTel SDK)https://github.com/Azure/azuremonitor-opentelemetry-profiler-netenablement-overview.md

    Present the enablement instructions to the user in a clear, step-by-step format. Include:

    • Prerequisites (e.g., "Always on" for App Service, Basic tier or higher)
    • The specific steps to enable the profiler
    • Any required NuGet packages and code changes (for EventPipe)
    • How to verify the profiler is running (log output to look for)

    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

  7. Verify the profiler is producing data — After the user has enabled the profiler and generated some traffic, re-run the check-profiler-status.md script to confirm profiler events are appearing. The profiler typically takes 2–5 minutes to start producing traces after enablement.

    • If both 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.
    • If only 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.
    • If no events appear after the expected wait time, suggest troubleshooting:
    • Verify the connection string is correct
    • Check the application logs for profiler startup messages
    • Ensure there is traffic hitting the application
    • For EventPipe: enable debug logging by setting log level for Microsoft.ServiceProfiler and Microsoft.ApplicationInsights.Profiler to Debug

    Once 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.

Key facts

  • The profiler adds 5–15% CPU/memory overhead when actively collecting traces (default: 30s every hour)
  • Profiler data is automatically deleted after 15 days
  • Only one profiler can be attached per web app
  • Code Optimizations and hot path analysis both depend on profiler data — without it, these features return no results

References

  • Profiler Agent Selection Guide
  • Enablement Overview
  • Check Profiler Status
  • Investigation Notes
  • resolve-app-id.md
  • az CLI Query Pitfalls

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.