Loading...

How to use Bicep to deploy Azure LogAnalytics Workspace and link Application Insights to it

How to use Bicep to deploy Azure LogAnalytics Workspace and link Application Insights to it

This post is part of a series

I like to deploy my Azure resources using Bicep - If you never heard about it, I blogged a while ago on how to get started with Bicep - please catch up first if you are not yet familiar with Bicep!

I strongly believe that we can’t meaningfully improve what we don’t measure. Especially though when it comes to improving apps, user feedback alone is sometimes not as reliable as we wanted it to be. This is why I like to monitor performance and track user behavior with Azure Application Insights.

Azure Application Insights

Application Insights is a tool in Azure that helps you keep an eye on your app’s performance and user activity. It tracks things like response times, errors, and failures so you can spot problems before users raise lots of tickets. You can get alerts, if something is off and of course as it is an Azure service, it works well with all kin of other Azure services.

For the longest time, Application Insights could store its data independently, but a couple of months ago Microsoft changed this and Application Insights now requires you to use a Log Analytics Workspace as the backend for storing telemetry data. This raises obviously the question: What is a Log Analytics workspace?

Azure Log Analytics Workspace

An Azure Log Analytics Workspace is like a central hub where you collect and analyze log data from various sources, including your Power Apps and Azure services.

When you use Application Insights to monitor your app’s performance, connecting it to a Log Analytics Workspace supercharges your capabilities:

  • It lets you run advanced queries to dig into your data and uncover insights that basic Application Insights might miss
  • If you’re tracking multiple apps or resources, a Log Analytics Workspace pulls all the data together in one place, making it easier to spot patterns and issues

How do we create now the Log Analytics Workspace and Application Insights?

Please make sure, that you installed the Bicep tools

We will work through this in modules. If you are not familiar with this approach yet, using modules in Bicep is all about making your infrastructure code more organized and reusable. Instead of having one big, messy file, you can break things down into smaller, more focused pieces. For this deployment, we will need 3 files. 1 for the Log Analytics Workspace, 1 for the Application Insights and 1 main, that will call the other ones. Let’s get started!

  1. Create a new bicep file, name it loganalyticsworkspace.bicep
param location string
param logAnalyticsWorkspaceName string
resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
name: logAnalyticsWorkspaceName
location: location
properties: {
sku: {
name: 'PerGB2018'
}
retentionInDays: 30
}
}
  1. Create a new bicep file, name it appinsights.bicep
param location string
param appInsightsName string
param applicationType string = 'web'
param logAnalyticsWorkspaceId string
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appInsightsName
location: location
kind: applicationType
properties: {
Application_Type: applicationType
WorkspaceResourceId: logAnalyticsWorkspaceId
}
}
  1. Create a new Bicep file, name in main.bicep
param location string = resourceGroup().location
param logAnalyticsWorkspaceName string
param appInsightsName string
param applicationType string = 'web'
// Deploy Log Analytics workspace
module logAnalytics 'logAnalyticsWorkspace.bicep' = {
name: 'logAnalyticsDeployment'
params: {
location: location
logAnalyticsWorkspaceName: logAnalyticsWorkspaceName
}
}
// Deploy Application Insights and link to Log Analytics workspace
module appInsights 'appInsights.bicep' = {
name: 'appInsightsDeployment'
params: {
location: location
appInsightsName: appInsightsName
applicationType: applicationType
logAnalyticsWorkspaceId: logAnalytics.outputs.logAnalyticsWorkspaceId
}
}
4. Now deploy this using Azure CLI
```azurecli
# Set variables
$RESOURCE_GROUP="yourResourceGroupName"
$LOCATION="yourLocation"
$LOG_ANALYTICS_WORKSPACE_NAME="yourLogAnalyticsWorkspaceName"
$APP_INSIGHTS_NAME="yourAppInsightsName"
# Create resource group if it doesn't exist
az group create --name $RESOURCE_GROUP --location $LOCATION
# Deploy the main Bicep file
az deployment group create \
--resource-group $RESOURCE_GROUP \
--template-file main.bicep \
--parameters logAnalyticsWorkspaceName=$LOG_ANALYTICS_WORKSPACE_NAME appInsightsName=$APP_INSIGHTS_NAME location=$LOCATION

đź’ˇ please make sure that you put actual values into the placeholders

As a result, we can now see

deployment worked

that the deployment worked like a charm! We can even see, that in fact, we have 4 deployments - One of them being Smart detection - Failure Anomalies, that gets automatically deployed. The other 3 are exactly the files that we created!

deployments

Bonus for Power Apps people

You can now link your Application Insight Instrumentation Key to a Canvas app an track its performance! OPen your app in EDIT mode, open the APP object and find the Instrumentation Key property on the right pane:

alt text

Conclusion

Bicep modules make it very easy to deploy Azure resources - If you’d like to take that one or two levels up, then stay tuned for next parts of this series… Where we cover how to utilize a Docker container to store our Bicep files org wide, and how to use this then in automated Azure DevOps pipeline!

Published on:

Learn more
Luise Freese: Consultant & MVP
Luise Freese: Consultant & MVP

Recent content on Luise Freese: Consultant & MVP

Share post:

Related posts

Azure Developer CLI (azd): Run and test AI agents locally with azd

New azd ai agent run and invoke commands let you start and test AI agents from your terminal—locally or in the cloud. The post Azure Developer...

1 day ago

Microsoft Purview compliance portal: Endpoint DLP classification support for Azure RMS–protected Office documents

Microsoft Purview Endpoint DLP will soon classify Azure RMS–protected Office documents, enabling consistent DLP policy enforcement on encrypte...

1 day ago

Introducing the Azure Cosmos DB Plugin for Cursor

We’re excited to announce the Cursor plugin for Azure Cosmos DB bringing AI-powered database expertise, best practices guidance, and liv...

2 days ago

Azure DevOps Remote MCP Server (public preview)

When we released the local Azure DevOps MCP Server, it gave customers a way to connect Azure DevOps data with tools like Visual Studio and Vis...

2 days ago

Azure Cosmos DB at FOSSASIA Summit 2026: Sessions, Conversations, and Community

The FOSSASIA Summit 2026 was an incredible gathering of developers, open-source contributors, startups, and technology enthusiasts from across...

3 days ago

Azure Cosmos DB at FOSSASIA Summit 2026: Sessions, Conversations, and Community

The FOSSASIA Summit 2026 was an incredible gathering of developers, open-source contributors, startups, and technology enthusiasts from across...

3 days ago

Dataverse: Avoid Concurrency issues by using Azure Service Bus Queue and Azure Functions

Another blog post to handle the concurrency issue. Previously, I shared how to do concurrency via a plugin in this blog post and also how to f...

4 days ago

March Patches for Azure DevOps Server

We are releasing patches for our self‑hosted product, Azure DevOps Server. We strongly recommend that all customers stay on the latest, most s...

5 days ago

Azure Developer CLI (azd): Debug hosted AI agents from your terminal

New azd ai agent show and monitor commands help you diagnose hosted AI agent failures directly from the CLI. The post Azure Developer CLI (azd...

6 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy