Terraform version: 0.12.17, 0.12.19, 0.12.24
AzureRm version : 1.44.0
Application Insight should be able to log messages from Azure Function App/other services
Nothing logged after I added the instrument key from Application Insight to Azure Function App
I tried to create an application insight manually (by portal without using Terraform) , and it can log the messages.
provider "azurerm" {
version = "~>1.44.0"
subscription_id = var.subscription_id
}
provider "azuread" {
}
terraform {
backend "azurerm" {
}
}
resource "azurerm_resource_group" "rg" {
name = "PocAI"
location = "australiaeast"
}
resource "azurerm_application_insights" "ai" {
name = "applicationInsight"
location = var.location
resource_group_name = azurerm_resource_group.rg.rg_name
application_type = "Web"
sampling_percentage = 0
}
resource "azurerm_log_analytics_workspace" "logworkspace" {
name = "logsapce"
location = var.location
resource_group_name = azurerm_resource_group.rg.rg_name
sku = "PerGB2018"
}
resource "azurerm_log_analytics_solution" "logsolution" {
solution_name = "ContainerInsights"
location = var.location
resource_group_name = azurerm_resource_group.rg.rg_name
workspace_resource_id = azurerm_log_analytics_workspace.logworkspace.id
workspace_name = azurerm_log_analytics_workspace.logworkspace.name
plan {
publisher = "Microsoft"
product = "OMSGallery/ContainerInsights"
}
}
@masonyc Thank you for submitting this issue!
I assume you have some existing function_app in azure, you want to create a application_insights via terraform and add that function_app into it. Then I think first you only need to create resource_group and application_insights in terraform (as analytics workspace/solution are not necessary for this use case):
provider "azurerm" {
version = "~>1.44.0"
subscription_id = var.subscription_id
}
variable "location" {
type = string
default = "australiaeast
}
resource "azurerm_resource_group" "rg" {
name = "PocAI"
location = var.location
}
resource "azurerm_application_insights" "ai" {
name = "applicationInsight"
location = var.location
resource_group_name = azurerm_resource_group.rg.name
application_type = "web"
sampling_percentage = 0
}
One possible issue I find from config is that if you set sampling_percentage to 0, then there will be no telemetry be picked by application_insights. Maybe you shall adjust it a bit.
After changing it to 100 (or remove it as 100 is the default value), I can see the function_app show up in the "Application Map" in application_insghts interface from portal.
Also wanna confirm the step you use to add function_app to application_insights. The step is like:
name to APPINSIGHTS_INSTRUMENTATIONKEY and set the value to the instrumentation key of application_insightsNormally you need to wait several seconds to minutes for the config take effect, then depending on your sampling rate, you shall see some telemetry from your application_insights interface.
BTW, since terraform azurerm provider v2.7.0, you can directly create a function_app with instrumentation key set so as to be added to application_insights. You may want to have a look.
@magodo Thanks for the quick reply. I can confirm it does work after I changed the sampling rate.
We had it like that for 4 months and it suddenly got broken from last week. My next question is any ideas why the 0 sampling rate worked before and now it doesn't?
Good news!
For the reason why it got broken from last week, one possibility is that after the first provision for this resource via terraform, somehow the sampling rate got adjusted outside of terraform. Then I assume you have triggered another apply on last week, which changes the sampling rate to 0. That's just some hypothetic case I can imagine.
I scanned through the code and didn't see any change will cause this breaking change.
That makes sense. Thank you for your help! @magodo
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!