Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function App log invocation with App Insights #2457

Closed
kamran-pervaiz opened this issue Dec 5, 2018 · 10 comments
Closed

Function App log invocation with App Insights #2457

kamran-pervaiz opened this issue Dec 5, 2018 · 10 comments

Comments

@kamran-pervaiz
Copy link

kamran-pervaiz commented Dec 5, 2018

Terraform Version

  • Terraform v0.11.9

Affected Resource(s)

  • azurerm_function_app

Terraform Configuration File(s)

module "resource_group" {
  source      = "git::ssh://address"
  environment = "${var.environment}"
  application = "${var.application}"
  app_version = "${var.app_version}"
}
resource "azurerm_application_insights" "application_insights" {
  name                = "${var.environment}-${var.application}-appInsights"
  location            = "${module.resource_group.location}"
  resource_group_name = "${module.resource_group.name}"
  application_type    = "Web"
}
module "function_app" {
  source                            = "git::ssh://address"
  environment                       = "${var.environment}"
  application                       = "${var.application}"
  resource_group_name               = "${module.resource_group.name}"
  app_version                       = "${var.app_version}"
  app_service_plan_id               = "${module.app_service_plan.id}"
  storage_primary_connection_string = "${module.storage_account.primary_connection_string}"
app_settings {
    "AppInsights_InstrumentationKey" = "${azurerm_application_insights.application_insights.instrumentation_key}"
  }
}

Expected Behavior
image

Actual Behavior
image

Difference
I have noticed the instrumentation key is indeed in app_settings but slot settings checkbox is not checked when I deploy using above terraform script but when I manually configure App Insights this checkbox is checked (below).

image

Other thing I found in the automation script generated by azure is, it has hidden link in tags of app_insights compared to what is generated by terraform (empty tags):

"tags": {
"hidden-link:/subscriptions/subscription_id/resourceGroups/rg_group_name/providers/microsoft.insights/components/int-content-notification-appInsights": "Resource"
}

any suggestion?

@tombuildsstuff
Copy link
Contributor

hey @kamran-pervaiz

Thanks for opening this issue :)

Unfortunately at this time the only means of linking an Application Insights resource to an App Service / Function App is via this (kinda hidden) tag linking the two resources. I've previously raised a request with Microsoft (through some internal channels) to be able to add an API Endpoint to be able to configure this independent of the two resources (since, it should be possible to configure both independently and then link the two, imo). I've not seen anything come of this yet - but if you're interested in this behaviour I'd recommend opening a bug on the Azure REST API Specs Repository repository requesting support for this.

From Terraform's perspective since App Services and Function Apps share the same underlying API (at this point in time at least) - I'm going to close this in favour of #1303 which is tracking a request for a resource linking Application Gateway's and App Services

Thanks!

@kamran-pervaiz
Copy link
Author

@tombuildsstuff thank you for quick reply, I tried hidden link but its not substituting the values, any idea how to do it?

resource "azurerm_application_insights" "application_insights" {
  name                = "${var.environment}-${var.application}-appInsights"
  location            = "${module.resource_group.location}"
  resource_group_name = "${module.resource_group.name}"
  application_type    = "Web"
  tags{
    "hidden-link:${module.resource_group.id}/providers/Microsoft.Web/sites/${module.function_app.name}" = "Resource"
  }
}

Terraform output is:

azurerm_application_insights.application_insights: Creating...

app_id: "" => ""
application_type: "" => "Web"
instrumentation_key: "" => ""
location: "" => "northeurope"
name: "" => "int-content-notification-appInsights"
resource_group_name: "" => "int-content-notification"
tags.%: "" => "1"
tags.hidden-link:${module.resource_group.id}/providers/Microsoft.Web/sites/${module.function_app.name}: "" => ""

@tombuildsstuff
Copy link
Contributor

@kamran-pervaiz it's hard to say without seeing more of the configuration being used, would you be able to post the rest of the configuration / confirm which outputs are available from the module?

@kamran-pervaiz
Copy link
Author

kamran-pervaiz commented Dec 5, 2018

thanks @tombuildsstuff for quick reply, below is my outputs.tf for resource-group.

output "id" {
  value = "${azurerm_resource_group.resource_group.id}"
}

function-app outputs.tf

output "name" {
  value = "${azurerm_function_app.function_app.name}"
}

@tombuildsstuff
Copy link
Contributor

@kamran-pervaiz the configuration looks valid - as such it could be that it's not possible to interpolate key values in Terraform 0.11; such that a virtual resource may be necessary in the interim here 🤔

@kamran-pervaiz
Copy link
Author

kamran-pervaiz commented Dec 7, 2018

@tombuildsstuff thank you for your reply, I managed to make hidden-link by using

Map()

function but for some reason it doesn't configure app insights for function app. There might be some other bits which needs configuring but when I click Configure (with hidden-link) it takes me to a graph like appinsights is attached.

image

another difference i found is that Configured features under function app doesn't list AppInsights with hidden-link compared to manually.

Expected Behavior:
image

Actual Behavior:
image

according to this link we just need to add only instrumation key: https://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring#new-function-app

Any suggestion is welcome.

@kamran-pervaiz
Copy link
Author

@tombuildsstuff found the problem.

AppInsights_InstrumentationKey should be APPINSIGHTS_INSTRUMENTATIONKEY <-- casing matters

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

@jamesbannan
Copy link

@kamran-pervaiz Can you please share how you generated the hidden-link tag using map()? I am trying to do the same thing with an App Service and associated App Insights instance

@jamesbannan
Copy link

Actually it's OK - I figured it out:
tags = "${map("hidden-link:${var.resource-group_id}/providers/Microsoft.Web/sites/${var.app-service_name}", "Resource")}"

@ghost
Copy link

ghost commented Mar 5, 2019

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!

@ghost ghost locked and limited conversation to collaborators Mar 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants