Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable Application Insights using Terraform?

Using Terraform, how do you enable Application Insights agent-based monitoring for

Azure App Service (.NET Core 2.x) Azure Function App (.NET Core 2.x)

like image 524
user2368632 Avatar asked Jul 07 '19 17:07

user2368632


2 Answers

To enable the Application Insights agent-based monitoring for Azure App Service (.NET Core 2.x) Azure Function App (.NET Core 2.x), you just need to add the environment variable for application insight in the app setting like below:

In Azure portal:

enter image description here

In terraform:

app_settings = {
    "APPINSIGHTS_INSTRUMENTATIONKEY" = "${azurerm_application_insights.example.instrumentation_key}"
  }

The result shows the logs for the function "functioninsighttest":

enter image description here

like image 52
Charles Xu Avatar answered Sep 23 '22 15:09

Charles Xu


Apparently now in 2021 there are two ways to this.

The second one is:

app_settings = {
    "MSDEPLOY_RENAME_LOCKED_FILES"                    = "1"
    "WEBSITE_HEALTHCHECK_MAXPINGFAILURES"             = "10"
    "ASPNETCORE_ENVIRONMENT"                          = "Development"
    "APPINSIGHTS_INSTRUMENTATIONKEY"                  = azurerm_application_insights.appi1.instrumentation_key
    "APPLICATIONINSIGHTS_CONNECTION_STRING"           = azurerm_application_insights.appi1.connection_string
    "APPINSIGHTS_PROFILERFEATURE_VERSION"             = "1.0.0"
    "APPINSIGHTS_SNAPSHOTFEATURE_VERSION"             = "1.0.0"
    "ApplicationInsightsAgent_EXTENSION_VERSION"      = "~2"
    "DiagnosticServices_EXTENSION_VERSION"            = "~3"
    "InstrumentationEngine_EXTENSION_VERSION"         = "disabled"
    "SnapshotDebugger_EXTENSION_VERSION"              = "disabled"
    "XDT_MicrosoftApplicationInsights_BaseExtensions" = "disabled"
    "XDT_MicrosoftApplicationInsights_Java"           = "1"
    "XDT_MicrosoftApplicationInsights_Mode"           = "recommended"
    "XDT_MicrosoftApplicationInsights_NodeJS"         = "1"
    "XDT_MicrosoftApplicationInsights_PreemptSdk"     = "disabled"
  }
like image 31
Maciek Avatar answered Sep 23 '22 15:09

Maciek