AppInsight_Bicep_update

Bicep IaC for an Azure Container App to use a pre-existing Application Insight instance, such that all the logging for Azure Container app is sent to an already created with the following id information:

Workspace= la-fsdi-shared

A: First, you need to update the Bicep file for your Azure Container App to reference the pre-existing Application Insights instance. The updated Bicep code can look like this:

var instrumentationKey = '<KEY>'
var connectionString = 'InstrumentationKey=<KEY>IngestionEndpoint=https://eastus-5.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'

var workspace = 'la-fsdi-shared'

resource app 'Microsoft.Web/sites@2021-01-15' = {
  name: 'yourContainerAppName'
  // Rest of your properties
  properties: {
    // Rest of your properties
    siteConfig: {
      appSettings: [
        {
          name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
          value: instrumentationKey
        },
        {
          name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
          value: connectionString
        }]
      }
  }
}

After this step, compile your Bicep file into an ARM template using the Azure CLI command:

az bicep build --file {your filepath to the bicep file}

Then deploy the generated .json file to Azure:

az deployment group create --resource-group {Your resource group} --template-file {Generated .json file path}

Once the deployment is completed, your Azure Container App should start sending logs to the referenced Application Insights instance.

Please replace the placeholder such as {yourContainerAppName}, {Your resource group}, and {your filepath to the bicep file} with your actual information.

Resources:

Last updated