Use Azure Monitor to collect logs, metrics, and alerts across your JavaScript applications and the Azure services they depend on. Azure Monitor is the central platform service that collects and stores your telemetry. You can instrument your applications with Application Insights. You should monitor your hosted application service, the Azure services the application integrates with, and the application source code itself.
Understand logs, metrics, and alerts
Telemetry is the data collected from your applications and services to monitor their health, performance, and usage. In Azure, telemetry is categorized into logs, metrics, and alerts.
Azure offers four kinds of telemetry:
Telemetry type
What it gives you
Where to find it for each service
Metrics
Numeric, time-series data (CPU, memory, etc.)
Metrics in portal or az monitor metrics CLI
Alerts
Proactive notifications when thresholds hit
Alerts in portal or az monitor metrics alert CLI
Logs
Text-based events and diagnostics (web, app)
App Service Logs , Functions Monitor, Container Apps Diagnostics
Custom logs
Your own application telemetry via App Insights
Your Application Insights resource’s Logs (Trace) table
Pick the right telemetry for your question:
Scenario
Use logs…
Use metrics…
Use alerts…
“Did my web app start and respond?”
App Service web-server logs (Logs)
N/A
N/A
“Is my function timing out or failing?”
Function invocation logs (Monitor)
Function execution duration metric
Alert on “Function Errors >0”
“How busy is my service and can it scale?”
N/A
Service throughput/CPU in Metrics
Autoscale alert on CPU% > 70%
“What exceptions is my code throwing?”
Custom Trace logs in Application Insights
N/A
Alert on “ServerExceptions >0”
“Have I exceeded my transaction or quota limits?”
N/A
Quota-related metrics (Transactions, Throttling)
Alert on “ThrottlingCount >0”
Cost optimization
You can significantly reduce your cost for Azure Monitor by understanding best practices for configuration options and opportunities to reduce the amount of data that it collects.
Enable logging and metrics for all Azure resources
Each service in Azure has its own logging and metrics capabilities. Enable logging on each Azure resource to ensure you have the telemetry you need to monitor your entire end to end application.
Create Azure Monitor resource
You can create an Azure Monitor resource to collect logs and metrics from your Azure resources. This resource is typically a Log Analytics workspace, which is where logs and metrics are stored.
You can create this resource in several ways:
Azure portal: Use the Azure portal to create a Log Analytics workspace and configure diagnostic settings for your resources.
Azure CLI: Use the Azure CLI to create a Log Analytics workspace and configure diagnostic settings for your resources.
PowerShell: Use PowerShell to create a Log Analytics workspace and configure diagnostic settings for your resources.
Bicep: Use Bicep templates to define and deploy your Azure Monitor resources declaratively.
Create a Log Analytics workspace using the Azure CLI
Use the Azure CLI to create a Log Analytics workspace, which is where logs and metrics are stored. Example:
Use Bicep to define and deploy your Azure Monitor resources declaratively. This example creates a Log Analytics workspace and configures diagnostic settings for an App Service:
Include logging, metrics, and alerting in your IaC templates with a [Bicep diagnosticSettings resource reference](/azure/templates/microsoft.insights/diagnosticsettings). Example (Bicep):
```bicep
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: 'myWorkspace'
location: resourceGroup().location
}
resource diagSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = {
name: '${webApp.name}/appServiceLogging'
properties: {
workspaceId: logAnalytics.id
logs: [
{ category: 'AppServiceConsoleLogs'; enabled: true }
{ category: 'AppServiceHTTPLogs'; enabled: true }
]
metrics: [
{ category: 'AllMetrics'; enabled: true }
]
}
}
Create alerts for your resources
You can set up alerts for metrics in the Azure portal or by using the Azure CLI. Alerts can include specific metrics, communication streams (such as email), and frequency.
Use the following examples to create metric alerts in the portal or programmatically:
Azure CLI: quick setup via az monitor metrics alert
Bicep: declarative IaC definition for Microsoft.Insights/metricAlerts
Alerts can specify target metrics, notification channels (email, webhook), severity, evaluation frequency, and action groups.
To view log data in the Azure portal, navigate to your Log Analytics workspace and select Logs. You can run Kusto Query Language (KQL) queries against the logs.
Stream logs
Use the following table to learn more about how to stream logs.
When developing locally, you can use the Azure MCP Servermonitor tool to query logs without leaving your IDE. Once you install the server, example Copilot prompts include:
List workspaces: "Show me all Log Analytics workspaces in my subscription."
Find tables: "List all tables in my workspace 'security-logs'"
Complex query: "Show me the CPU usage trend for my web servers over the last 24 hours"
Add logging to your code
For application logging, Application Insights can provide:
Standard logging in the Azure service and in your source code, depending on the initialization.
Custom logging from your deployment pipeline and in your source code.
Standard console logging (stdout/stderr)
Azure web apps and Azure Functions automatically provide custom logging to stdout and stderr, if you use the correct logging functions:
Web apps use console.log('your message here').
Function apps use context.log('your message here').
Add custom Application Insights logging
You can add richer custom logging by using Application Insights in Azure Monitor. Application Insights offers server (Node.js) and client (browser) scenarios:
Add the Application Insights SDK to your source code.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.
Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.