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 Backup-SAP HANA DB Backup Delivers More Value at Lower TCO with Reduced Protected Instance Fee

Azure Backup for SAP HANA Database Delivers More Value at Lower TCO with Reduced Protected Instance Fees starting 1st Sept’2024   At Azur...

11 hours ago

Utilizing Azure DDoS Protection Workbook for DDoS attack traffic Analysis

In today's digital age, the security of applications, servers, and networks is paramount. One of the most significant threats to this security...

1 day ago

How to secure access to an Azure Container registry with a Managed Identity and RBAC

This post is part of a series How to deploy Azure LogAnalytics Workspace and link Application Insights to it How to use Azure Container Regi...

2 days ago

Unified Routing – Diagnostics in Azure

You may (or may not) be aware that the diagnostics option in Unified Routing has been deprecated. It is being replaced by diagnostics in Azure...

3 days ago

Service health and Message center: Azure Information Protection consolidation

This post is about the consolidation of Azure Information Protection communications under Microsoft Purview in Service Health and Message Cent...

3 days ago

Switch to Azure Business Continuity Center for your at scale BCDR management needs

In response to the evolving customer requirements and environments since COVID-19, including the shift towards hybrid work models and the incr...

3 days ago

Optimizing Azure Table Storage: Automated Data Cleanup using a PowerShell script with Azure Automate

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

3 days ago

Microsoft Fabric: Resolving Capacity Admin Permission Issues in Automate Capacity Scaling with Azure LogicApps

A while back, I published a blogpost explaining how to use Azure LogicApps to automate scaling Microsoft Fabric F capacities under the PAYG (P...

3 days ago

The Azure Storage product group is heading to the SNIA Developer Conference 2024

The Azure Storage product group is heading to the SNIA Developer Conference (SDC) 2024 in Santa Clara, California, USA from September 16th thr...

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