In today’s cloud-centric world, effective monitoring is key to maintaining the health of any application. Azure Application Insights (App Insights) is a powerful tool that helps developers gain real-time insights into their applications’ performance and usage patterns. Whether you’re running applications in the cloud, on-premise, or in a hybrid environment, App Insights offers actionable insights to optimize performance, detect issues, and enhance user experience.
This blog will dive into the core features, benefits, and best practices for using Azure Application Insights.
What is Azure Application Insights?
Azure Application Insights is an Application Performance Management service designed to monitor live applications. Part of the Azure Monitor suite, it helps developers and IT professionals track performance anomalies, diagnose issues, and understand how users are interacting with applications.
App Insights can monitor a variety of application types, including web applications, services, and APIs—whether hosted on Azure, on-premise, or other clouds. By integrating App Insights into your application, you gain access to rich telemetry data, including request rates, response times, dependency failures, and custom events.
Key Features of Azure Application Insights
- Real-time Monitoring and Alerts: Track key metrics in real-time and set up alerts for proactive issue management.
- End-to-End Transaction Tracking: Monitor user requests across the entire application lifecycle for diagnosing performance issues.
- Automatic and Custom Telemetry: Automatically collect essential telemetry and send custom metrics for targeted monitoring.
- Smart Diagnostics with AI-Powered Insights: Utilize machine learning to detect anomalies and suggest root causes of performance issues.
- Log Analytics: Leverage Azure Log Analytics for advanced querying and visualization of telemetry data.
- Integration with Development Tools: Debug live applications and automate workflows directly within development environments like Visual Studio and Azure DevOps.
Benefits of Using Azure Application Insights
- Faster Time to Resolution: Quickly identify and resolve performance bottlenecks and errors to enhance operational efficiency.
- Improved Application Performance: Optimize code and infrastructure through continuous monitoring and performance insights.
- Enhanced User Experience: Analyze user interactions to refine application performance and boost user satisfaction.
- Cost-Effective Monitoring Solution: Enjoy a flexible, pay-as-you-go pricing model that suits businesses of all sizes without hefty upfront costs.
How to create application insights resources and connect with applications?
To create Application Insights in Azure, follow these steps:
Step 1: Navigate to the Azure Portal
Go to the Azure Portal and sign in with your credentials.
Step 2: Create a New Application Insights Resource
- Search for Application Insights:
- In the search bar at the top of the portal, type “Application Insights” and select Application Insights from the search results.
- Add a New Application Insights Resource:
- Click the + Create button at the top of the Application Insights page.
- Configure Your Application Insights Resource:
- On the Create Application Insights page, provide the following details:
- Subscription: Select the appropriate Azure subscription.
- Resource Group: Either select an existing resource group or create a new one.
- Name: Enter a unique name for the Application Insights resource.
- Region: Choose the region where you want to deploy the Application Insights resource.
- Resource Mode: Choose between Classic or Workspace-based. The Workspace-based mode allows better integration with Log Analytics and advanced monitoring features.
- On the Create Application Insights page, provide the following details:
- Review + Create:
- After configuring the settings, click Review + Create, and then click Create to deploy the resource.
Step 3: Set Up Instrumentation for Your Application/connect your app and application insights resource
Once the Application Insights resource is created, you can start monitoring your application by adding instrumentation code to it.
- Instrumentation Key:
- After the Application Insights resource is created, navigate to its Overview section, where you’ll find the Instrumentation Key and Connection String.
- Use this Instrumentation Key or Connection String in your application to connect it with Application Insights for telemetry data.
- Add Application Insights SDK:
- If you’re using a language like Python, Node.js, or .NET, you need to install the relevant Application Insights SDK and use the instrumentation key.
For example, in Python:
opencensus-ext-azure
Then, in your Python app:
from opencensus.ext.azure.trace_exporter import AzureExporter from opencensus.trace.samplers import ProbabilitySampler from opencensus.trace.tracer import Tracer tracer = Tracer( exporter=AzureExporter( connection_string="InstrumentationKey=<your-instrumentation-key>" ), sampler=ProbabilitySampler(1.0), )
Step 4: Monitor Your Application
Once your app is running with the configured instrumentation, you can start monitoring it via the Application Insights dashboard in Azure.
- Navigate to Your Application Insights Resource:
- Go back to the Application Insights resource you created.
- Live Metrics Stream:
- You can view real-time telemetry data using Live Metrics Stream to see incoming requests, CPU usage, memory consumption, and more.
- Metrics Explorer:
- Use the Metrics Explorer to create custom metrics charts and dashboards for deeper insights into your application’s performance.
By following these steps, you can easily set up Application Insights to monitor and analyze your application’s performance in Azure.
Instrument the application running on local machine
Please copy all the files to understand app insights from the source code. Look into the app.py file under traces folder. The application is instrumented with log exporter. Add a connection string in the app.py code, which you got from azure portal (app insights overview). That’s it. your application is ready to produce logs!!!!
Logs from the development environment
Run the following command to run your application locally.
pip install -r requirements.txt
python app.py
Verify on Azure portal
Navigate in application insights resource and select logs from monitoring, Write query for logs as “traces”
Now explore a bit more and add metrics from the metrics menu residing in monitoring. Choose the option like server requests to get a chart.
In application insights overview we can see this graphs,
Next, we will enable live metrics using configure_azure_monitor class.
Implementation to enable Live metrics
Create a python application and add a few lines of code to export live metrics.
from azure.monitor.opentelemetry import configure_azure_monitor # Configure Azure Monitor for OpenTelemetry with live metrics enabled configure_azure_monitor( connection_string="<your_connection_string>", enable_live_metrics=True )
Navigate to the live-metrics folder, open the app.py file, and enter your actual connection string in the configure_azure_monitor
function.
Next, Run the application on the local machine.
pip install -r requirements.txt
python app.py
View live metrics in application insights, go to investigate from the menu and select live metrics.
We will see how to set up and view Application Insights for apps running on an AKS cluster in the next section.
Implementation to get insights of application running on AKS
When enabling Azure Monitor in an AKS cluster, we do not need to provide an explicit connection string like we would in an individual application using Application Insights. Instead, Azure Monitor automatically collects telemetry data from our Kubernetes cluster.
We can get pod logs through enabling monitoring while creating clusters or update our existing cluster like,
az aks enable-addons --addons monitoring --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP
Deploy an application using deployment.yaml on AKS cluster. if you don’t have AKS cluster follow our post to create one.
$ kubectl apply deployment.yaml
Our app is running inside a pod.
$ kubectl get svc
Use load balancer IP to browse our application.
Go to the azure portal. Select our cluster and navigate monitoring select insights to view CPU & Memory usage, Node counts, active pods et c in cluster tab.
Select the Containers tab to view the container list. Select a container to see the details of containers.
Click on a particular container to view the details.
Click on view in Log Analytics tab to see the container logs.
Application Insights offers a broad range of features and capabilities to help you monitor and diagnose your application’s performance.
Conclusion
Azure Application Insights offers a comprehensive monitoring solution for applications of all types. Its rich set of features—from real-time performance tracking to AI-driven insights—helps developers and IT professionals ensure their apps run smoothly, deliver optimal performance, and provide an exceptional user experience.
Whether you’re a seasoned developer or just starting out, integrating App Insights into your application architecture can provide immense value by reducing downtime, improving performance, and delivering actionable insights.