Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Diagnosing your application's performance issues can be difficult, especially when your app runs in a production environment in the dynamic cloud. Infrastructure, framework, or application code that handles the request in the pipeline might cause slow responses in your application.
Code Optimizations, an AI-based service in Azure Application Insights, works in tandem with the Application Insights Profiler for .NET. Together, they detect CPU and memory usage performance issues at a code level. They provide recommendations on how to fix those issues.
Make informed decisions and optimize your code using real-time performance data and insights gathered from your production environment.
Code Optimizations and Application Insights Profiler for .NET
The .NET Profiler and Code Optimizations work together to provide a holistic approach to performance issue detection.
Code Optimizations
Code Optimizations identifies, analyzes, and resolves the profiling data collected by the Application Insights Profiler for .NET. As the .NET Profiler uploads data to Application Insights, our machine learning model analyzes some of the data to find where the application's code can be optimized. Code Optimizations:
- Displays aggregated data gathered over time.
- Connects data with the methods and functions in your application code.
- Narrows down the culprit by finding bottlenecks in the code.
- Provides code-level performance fixes based on insights.
Analyze
After your environment's data is collected from the .NET Profiler traces and Snapshot Debugger snapshots, if enabled, Code Optimizations provides code-level recommendations on an hourly basis. By default, the aggregated data view shows a rolling 24-hour window of recently identified issues, with a 30-day history for you to review and analyze past events.
Resolve
After you identify and analyze Code Optimizations, you can use the Copy details button in the Azure portal to manually bring the insight context to your favorite tool, like GitHub Copilot.
Application Insights Profiler for .NET
The .NET Profiler focuses on tracing specific requests, down to the millisecond. It provides an excellent big picture view of issues in your application and general best practices to address them.
With Application Insights Profiler for .NET, you can capture, identify, and view performance traces for your application running in Azure, regardless of the scenario. The .NET Profiler trace process occurs automatically, at scale, and doesn't negatively affect your users. The .NET Profiler identifies:
- The median, fastest, and slowest response times for each web request made by your customers.
- The hot code path spending the most time handling a particular web request.
Enable the Profiler for .NET on all your Azure applications to gather data with the following triggers:
- Sampling trigger: Starts Profiler randomly about once an hour for two minutes.
- CPU trigger: Starts Profiler when the CPU usage percentage is over 80 percent.
- Memory trigger: Starts Profiler when memory usage is above 80 percent.
Each of these triggers can be configured, enabled, or disabled.
Cost and overhead
Code Optimizations are generated automatically after Application Insights Profiler for .NET is enabled. By default, Profiler actively collects traces every hour for 30 seconds or during periods of high CPU or memory usage for 30 seconds. The hourly traces (called sampling) are great for proactive tuning. The high CPU and memory traces (called triggers) are useful for reactive troubleshooting.
Note
When the Application Insights Profiler for .NET is actively running and collecting traces, it typically adds between 5% to 15% of CPU and memory overhead to your server.
There is no additional cost for storing data captured by .NET Profiler. The data is automatically deleted after 15 days.
Some Code Optimizations features, such as code-level fix suggestions, require Copilot for GitHub.
Enabling .NET Profiler
As frameworks and Azure services evolve, you can enable .NET Profiler for your .NET apps running on Azure by using different options.
| Azure service | How to enable | Details |
|---|---|---|
| Most Azure services | Code change in your application (most universal) |
If your .NET app runs on variants of Azure PaaS services or Containers, you can choose between two options for enabling .NET Profiler: - Application Insights Profiler for ASP.NET Core that uses the Application Insights SDK, or - New Azure Monitor OpenTelemetry Profiler for .NET (Preview) that uses Azure Monitor OpenTelemetry Distro |
| Azure App Service | No code change for your application | Because the Profiler is preinstalled, you can enable Profiler for .NET in the Azure portal for: - Azure App Service - .NET app on Windows - Azure Functions - App Service plan |
| Virtual Machines | No code change for your application | After the Application Insights SDK is enabled in your application code, you can enable the Profiler for .NET in your ARM template. - Azure Virtual Machines and Virtual Machine Scale Sets for Windows - Azure Service Fabric |
Details and examples for enabling Profiler for .NET
-
- Azure Container Apps
- Azure Kubernetes Services
- Azure Container Instances
Azure Virtual Machines and Virtual Machine Scale Sets for Windows
Note
You can also use the Java Profiler for Azure Monitor Application Insights, currently in preview.
Supported regions
Code Optimizations is available in the same regions as Application Insights. You can check the available regions using the following command:
az account list-locations -o table
You can set an explicit region using connection strings. For more information, see Connection string examples.
Limitations
Profiler
- Profiling web apps:
- You can use the .NET Profiler at no extra cost, although your web app must be hosted, at minimum, in the Basic tier of the Web Apps feature.
- You can attach only one profiler to each web app.
Code Optimizations
- Storage requirements:
- Currently, Code Optimizations only works with the default Profiler or Application Insights storage. It's not compatible with Bring-Your-Own-Storage (BYOS).
Troubleshooting
Profiler
If you enabled the Profiler for .NET but aren't seeing traces, see the Troubleshooting guide.
Code Optimizations
Running into issues? Check the Code Optimizations troubleshooting guide for scenario solutions.
Related content
Learn how to enable the .NET Profiler with Code Optimizations on your Azure service: