Skip to content

Commit

Permalink
[AppService] az functionapp create: Use app insights connection str…
Browse files Browse the repository at this point in the history
…ing instead of instrumentation key (Azure#27803)
  • Loading branch information
kamperiadis authored and MaxHorstmann committed Jan 19, 2024
1 parent 134014f commit 5e6f36f
Show file tree
Hide file tree
Showing 5 changed files with 1,146 additions and 298 deletions.
25 changes: 15 additions & 10 deletions src/azure-cli/azure/cli/command_modules/appservice/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3724,6 +3724,15 @@ def get_app_insights_key(cli_ctx, resource_group, name):
return appinsights.instrumentation_key


def get_app_insights_connection_string(cli_ctx, resource_group, name):
appinsights_client = get_mgmt_service_client(cli_ctx, ApplicationInsightsManagementClient)
appinsights = appinsights_client.components.get(resource_group, name)
if appinsights is None or appinsights.connection_string is None:
raise ResourceNotFoundError("App Insights {} under resource group {} was not found.".format(name,
resource_group))
return appinsights.connection_string


def create_functionapp_app_service_plan(cmd, resource_group_name, name, is_linux, sku, number_of_workers=None,
max_burst=None, location=None, tags=None, zone_redundant=False):
SkuDescription, AppServicePlan = cmd.get_models('SkuDescription', 'AppServicePlan')
Expand Down Expand Up @@ -4133,9 +4142,9 @@ def create_functionapp(cmd, resource_group_name, name, storage_account, plan=Non
site_config.app_settings.append(NameValuePair(name='APPINSIGHTS_INSTRUMENTATIONKEY',
value=app_insights_key))
elif app_insights is not None:
instrumentation_key = get_app_insights_key(cmd.cli_ctx, resource_group_name, app_insights)
site_config.app_settings.append(NameValuePair(name='APPINSIGHTS_INSTRUMENTATIONKEY',
value=instrumentation_key))
app_insights_conn_string = get_app_insights_connection_string(cmd.cli_ctx, resource_group_name, app_insights)
site_config.app_settings.append(NameValuePair(name='APPLICATIONINSIGHTS_CONNECTION_STRING',
value=app_insights_conn_string))
elif disable_app_insights or not matched_runtime.app_insights:
# set up dashboard if no app insights
site_config.app_settings.append(NameValuePair(name='AzureWebJobsDashboard', value=con_string))
Expand Down Expand Up @@ -4274,7 +4283,7 @@ def try_create_workspace_based_application_insights(cmd, functionapp, workspace_
}

appinsights = app_insights_client.components.create_or_update(ai_resource_group_name, ai_name, ai_properties)
if appinsights is None or appinsights.instrumentation_key is None:
if appinsights is None or appinsights.connection_string is None:
logger.warning(creation_failed_warn)
return

Expand All @@ -4283,12 +4292,8 @@ def try_create_workspace_based_application_insights(cmd, functionapp, workspace_
'You can visit https://portal.azure.com/#resource%s/overview to view your '
'Application Insights component', appinsights.name, appinsights.id)

if not is_centauri_functionapp(cmd, ai_resource_group_name, ai_name):
update_app_settings(cmd, functionapp.resource_group, functionapp.name,
['APPINSIGHTS_INSTRUMENTATIONKEY={}'.format(appinsights.instrumentation_key)])
else:
update_app_settings(cmd, functionapp.resource_group, functionapp.name,
['APPLICATIONINSIGHTS_CONNECTION_STRING={}'.format(appinsights.connection_string)])
update_app_settings(cmd, functionapp.resource_group, functionapp.name,
['APPLICATIONINSIGHTS_CONNECTION_STRING={}'.format(appinsights.connection_string)])


def try_create_application_insights(cmd, functionapp):
Expand Down
Loading

0 comments on commit 5e6f36f

Please sign in to comment.