How to use Azure Monitor for Application Insights
You can use Azure Monitor for Application Insights by taking a few easy steps. First, you need to set up your resource. Then, connect your application and start watching it. You can check how it works in real time. You can see what users do and find problems fast. Many companies use these tools to make their apps better, fix issues, and learn about users.
You get quick ideas and can save money by doing these steps.
Key Takeaways
Set up Application Insights in Azure to check your app’s health and what users do right now.
Use the Application Insights SDK to gather data like requests, errors, and custom events from your app.
Connect Application Insights with Azure Monitor, Log Analytics, and OpenTelemetry for better insights and easier problem solving.
Make alerts and dashboards to find problems fast and keep your app working well.
Save money by using sampling, turning off extra data collection, and setting daily limits on telemetry.
Overview
What Is Azure Monitor?
Azure Monitor helps you keep an eye on your resources. You can watch things in the cloud and on your own computers. It collects data from places like virtual machines, containers, and databases. You can also get data from custom sources. The system puts all the metrics and logs together in one spot. You get tools to see, study, and act on what is happening.
You can set up action groups and alerts to help you react fast when there is a problem.
The platform works with hybrid and multi-cloud setups, so you can check resources inside and outside Azure.
You can use dashboards, workbooks, and Power BI to look at your data in ways that help you.
What Is Application Insights?
Application Insights lets you see how your app works and how people use it. First, you make an Application Insights resource in Azure. Next, you add the SDK to your app and connect it with a key or connection string. The SDK gathers data about requests, errors, dependencies, and how well your app runs.
Tip: You can use manual tracking to record special events or numbers that matter most to you.
The data goes to Azure, and you can see it right away. You can set up sampling to control how much data you send, which helps save money. If you want to keep data longer or study it more, you can send it to outside storage.
Key Benefits
You get a full view of your apps and resources. You can make smarter choices, boost performance, and keep users happy.
Setup
Create Application Insights Resource
You must make an Application Insights resource before you can watch your app. Here are the steps to set it up in the Azure Portal:
Log in to the Azure portal.
Click "Create a resource."
Pick Application Insights from Monitoring & Diagnostics.
Type in the name, region, and resource group for your resource.
Check your info and create the Application Insights resource.
Note: If you do not pick a Log Analytics workspace, Azure will make one for you. You can see the workspace in the Application Insights Overview after setup.
Making your resource is the first thing you do to use Azure Monitor. This helps you track how your app is doing.
Configure in Azure Portal
After you make your Application Insights resource, you need to set it up for your app. You can link your app service or function in the Azure Portal. Most settings are in your app’s files, like ApplicationInsights.config or .xml. You can turn telemetry modules on or off. You can set up sampling and add connection strings. Telemetry initializers let you add special data to your logs.
Tip: Use connection strings instead of instrumentation keys. Connection strings help your data get to Azure Monitor better.
You can manage your resource and see your data in the Azure Portal. You can also make alerts and dashboards to watch your app live.
SDK and Instrumentation
You need to add the Application Insights SDK to your app to start collecting data. The SDK works with many languages:
.NET
Java
Node.js
PHP
Ruby
Python
You can use the TelemetryClient API if you want to track things by hand. The SDK tracks requests, page views, calls, messages, and errors. You can also make the SDK collect special data for you.
Here are some best practices for instrumenting your app:
Choose the right way to instrument. Use autoinstrumentation if you do not need to track things by hand. Autoinstrumentation is easier and safer.
Use connection strings for better data delivery.
Keep your SDKs updated. Update at least once a year for new features and fixes.
Work with your monitoring team to plan and fix problems.
Use sampling to control how much data you send and save money.
Make one Application Insights resource for each workload and environment. This keeps your data neat.
Use managed identities and Microsoft Entra ID for login. This means you do not need to handle passwords.
Test your app to see how it acts when things go wrong. Practice how to recover.
Make sure your setup can handle more data as your app grows.
Use code to set up your settings again fast after a problem.
Remember: Good instrumentation helps you find problems fast and keeps your app working well.
Now you can use Azure Monitor and Application Insights together. You can watch your app, look at data, and make your app better.
Integration with Azure Monitor
App Services and Functions
You can connect Application Insights to Azure App Services and Azure Functions. This helps you collect data and watch your apps live. Here is what you do:
Log in to the Azure Portal.
Go to 'All resources' and filter by your subscription and type, like Function App or App Service.
Pick the app you want to watch.
In the menu, find 'Monitoring' and click 'Application Insights'.
If it is not on, click 'Turn on Application Insights'.
You can make a new Application Insights resource or use one you already have.
Save your changes to link Application Insights to your app.
If you use the CLI, you can list your subscriptions and pick one. Then, list your Function Apps and check their settings. Use commands to set the Application Insights connection string or key.
Do these steps for each app you want to watch.
Tip: When you make a new Function App, you can turn on Application Insights right away. The system adds the connection key for you.
This setup makes sure your apps send data to Application Insights. You can use Azure Monitor to see live numbers, track errors, and study what users do. If you run your app on your own computer, add the key to your local settings file to collect data while you build.
You get deep, live info for your apps. For virtual machines, you use agents to send data to Log Analytics, which checks the computer itself.
OpenTelemetry Support
OpenTelemetry gives you a way to collect logs, numbers, and traces from your apps. You can use it with Application Insights to see your whole system. Here is how you set it up:
Add the Azure Monitor OpenTelemetry Distro to your .NET app. In your settings, use
AddOpenTelemetry().UseAzureMonitor()
.Give your Application Insights connection string or key.
Set how much data you want to collect.
Add more OpenTelemetry sources or auto-instrumentation, like gRPC client or custom ActivitySource.
You can also set up metrics collection.
If you want, use files like appsettings.json to set your connection string and logging levels.
Run your app and check the Azure Portal to see your data in Application Insights.
Note: OpenTelemetry helps you follow requests across services. It uses special headers, so you can track a request from start to end, even if it moves between apps.
OpenTelemetry has many good points:
It makes collecting logs, numbers, and traces the same everywhere.
You get one view of your apps, so you find problems fast.
It works with many tools, so you are not stuck with one company.
You can pick what data to send, which saves money and keeps things clear.
It is easier to set up checks for cloud and big systems.
When you use OpenTelemetry with Application Insights and Azure Monitor, you get strong tools to watch your apps.
Log Analytics
You can connect Application Insights to Log Analytics for better searching and pictures. This lets you use Kusto Query Language (KQL) to look through your data.
To connect Application Insights to Log Analytics, do these steps:
In the Azure Portal, go to your Application Insights resource.
Link it to a Log Analytics workspace by giving your login info, subscription, group, and workspace name.
Once linked, you can write KQL queries to look at your data. For example, you can search for all trace messages with a certain phrase:
traces | where message contains "FunctionCallEfsApi no messages"
You can show your query results as tables or pictures. You can also set time ranges for your searches.
If you use Logic Apps, you can make reports happen by themselves. Add an action to send an email with your query results as an attachment.
Tip: If you link more than one Application Insights resource to the same Log Analytics workspace, you can search across them all. Use filters to see only the data you need.
Log Analytics gives you strong tools to look at your app data. You can count, group, and show events over time. This helps you see patterns, find problems, and make better choices with Azure Monitor.
Monitor and Analyze
Metrics and Telemetry
You can use metrics and telemetry in Application Insights to check your app’s health. Metrics are numbers that show things like speed or errors. Telemetry gives details about requests, problems, and what users do.
You can use TelemetryClient in your code to make custom metrics. Track events and numbers that matter to your business. Add extra details so you can sort and study data later.
Tip: Add up your custom metrics before you send them. This keeps your data small and your app quick.
Logs and Dashboards
Logs show what happens inside your app. You can search for errors or see what users do. Use the Azure portal to open the Logs tab and write Kusto queries. You can show results as charts, tables, or doughnut graphs.
Make dashboards to watch important numbers. Add tiles for things like request time or CPU use. Move and resize tiles to fit what you need. You can share dashboards with your team and set filters for each tile.
Pin charts from log searches to dashboards.
Use custom dashboards to watch things live.
Arrange tiles to show the most important numbers.
Alerts and Notifications
Set alerts to know when something is wrong. Application Insights has different alert types:
Log search alerts from your own queries.
Smart detection alerts use machine learning to find problems.
Service health and resource health alerts for Azure resources.
To make an alert, pick a metric or write a log query. Set the limit and choose who gets the alert. Use action groups to send emails or messages when alerts happen.
Note: Smart alerts change limits by themselves, so you get fewer false alarms.
User Tracking
Watch how users use your app to make it better. Look at things like time to insight, click counts, and session recordings. Funnel analysis shows where users stop using your app. Heatmaps show where users click the most.
Record sessions to find problems.
Study retention and churn to see if users are happy.
These ideas help you make your app easier and keep users happy. Azure Monitor puts all this data together so you can act fast and improve your app.
Troubleshooting
Common Issues
You might run into some problems when using Application Insights. Here are some things that can go wrong:
Some DLLs in your app’s bin folder, like Microsoft.ApplicationInsights.dll or System.Diagnostics.DiagnosticSource.dll, might stop monitoring from working. Visual Studio can add these files even if you do not use them.
Tests can fail even if your site looks okay. This can happen if your server does not use TLS 1.3.
If scripts or images do not load, strict checks on requests can make things fail.
Network issues or timeouts can stop tests after two minutes.
Some problems only show up in certain places because of network or CDN trouble.
You may not get alert emails if you set up action groups or email rules wrong.
Webhook alerts will not work if the app that gets them is down.
Firewalls can block agents and cause "403 Forbidden" errors.
If you send too much unique data, you can hit cardinality limits. Reports then show "Other values."
Sampling settings can make some server-side telemetry go missing.
Multi-step tests might not work because of size limits or features that are not supported.
Tip: Try using PerfView or Sysinternals to find DLL problems and other hidden issues.
Diagnostics Tools
Application Insights has many tools to help you fix problems. Here is a table that shows what each tool does:
These tools help you find missing telemetry, track errors, and study problems. The timeline and details show where things go wrong.
Best Practices
Here are some best ways to make your monitoring and troubleshooting better:
You should also set clear rules for how long to keep data, look for trends, and use dashboards that match your goals. Only give dashboard access to people who need it. Use reports to keep track of both operations and security.
Cost Optimization
Pricing Overview
You pay for Application Insights by how much data your app sends. The biggest cost is from data going in and being stored. Each gigabyte (GB) costs about $2.24. If your app sends 1 GB every day, you might pay $69 a month. You also pay more for alerts, web tests, and keeping data longer. Standard metrics from Azure are free. Custom metrics and using the REST API can cost extra. Alerts cost more if you set up lots of signals or send many notifications.
Here is a quick look at what changes your bill:
You can use Microsoft Cost Management + Billing to check your spending. This tool helps you find ways to save money.
Reduce Monitoring Costs
You can lower your monitoring costs by using smart steps. First, switch to workspace-based Application Insights. This lets you use basic logs, commitment tiers, and control how long you keep data. Use sampling to send only some of your telemetry data. Fixed-rate sampling keeps a set percent. Adaptive sampling changes the amount based on traffic.
Limit Ajax calls and turn off telemetry modules you do not need. You can change your ApplicationInsights.config file or use the DisableTelemetry flag in your code. Change log levels in your settings to collect only important logs. Add up metrics before sending them to lower the number of data points.
Here are some easy steps:
Use sampling to control data and save money.
Turn off modules that collect data you do not need.
Limit custom metrics to avoid extra alert costs.
Keep your SDKs updated for better use.
Set daily caps on telemetry data.
Check your logs in the Azure Portal to find costly tables and filter out logs you do not need.
Tip: Workspace-based Application Insights gives you more ways to manage costs. You can set rules for how long to keep data and use table changes to filter out expensive logs.
By using these ideas, you keep your monitoring working well and your costs low. You get the info you need without spending too much.
You can use Azure Monitor for Application Insights to make your app better. First, set up your resources and connect your app. Watch important numbers to see how your app is doing. Here are some steps to help you do well:
Set a daily limit and use sampling to save money.
Keep your tools updated and set alerts to act fast.
Make clear goals for how your app should work and fix your code.
Use strong security to keep your data safe.
Make a plan to keep your app working and fix it quickly if needed.
Try out advanced features to learn more and keep your app working well. 🚀
FAQ
How do you enable Application Insights for an existing app?
You open your app in the Azure Portal. Go to the "Application Insights" section. Click "Enable." Choose an existing resource or create a new one. Save your changes. Your app starts sending data right away.
Can you use Application Insights with apps not hosted in Azure?
Yes, you can. Add the Application Insights SDK to your app. Use your connection string. Your app sends data to Azure, even if it runs on your own server or another cloud.
What data does Application Insights collect by default?
Application Insights collects requests, exceptions, dependencies, performance counters, and user sessions. You see how your app works and where problems happen. You can add custom events if you want more details.
How do you control the amount of data sent to Application Insights?
You use sampling. Set a fixed rate or let the system adjust it. Sampling keeps important data and lowers your costs. You can change sampling settings in your app’s configuration.
Is your data safe in Application Insights?
Yes. Azure encrypts your data in transit and at rest. You control who can see your data. Use managed identities and strong access rules for extra safety.