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

[AppService] az functionapp create: Use app insights connection string instead of instrumentation key #27803

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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