Skip to content

Commit

Permalink
Use app insight connection string instead of aiKey (#4291)
Browse files Browse the repository at this point in the history
  • Loading branch information
nturinski authored Sep 24, 2024
1 parent d9e5cb4 commit d38ea09
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/commands/createFunctionApp/FunctionAppCreateStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ export class FunctionAppCreateStep extends AzureWizardExecuteStep<IFunctionAppWi

if (context.appInsightsComponent) {
appSettings.push({
name: 'APPINSIGHTS_INSTRUMENTATIONKEY',
value: context.appInsightsComponent.instrumentationKey
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING',
value: context.appInsightsComponent.connectionString
});

if (isElasticPremium && context.newSiteStack?.stack.value === 'java') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ContainerizedFunctionAppCreateStep extends AzureWizardExecuteStep<I
},
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING',
value: `InstrumentationKey=${context.appInsightsComponent?.instrumentationKey}`
value: context.appInsightsComponent?.connectionString
},
{
name: 'FUNCTIONS_EXTENSION_VERSION',
Expand Down
5 changes: 3 additions & 2 deletions src/commands/logstream/startStreamingLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ export async function startStreamingLogs(context: IActionContext, treeItem?: Slo
async function openLiveMetricsStream(context: IActionContext, site: ParsedSite, node: AzExtTreeItem): Promise<void> {
const client = await site.createClient(context);
const appSettings: StringDictionary = await client.listApplicationSettings();
const aiKey: string | undefined = appSettings.properties && appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY;
const aiKey: string | undefined = appSettings.properties &&
(appSettings.properties.APPLICATIONINSIGHTS_CONNECTION_STRING || appSettings.properties.APPINSIGHTS_INSTRUMENTATIONKEY);
if (!aiKey) {
// https://github.com/microsoft/vscode-azurefunctions/issues/1432
throw new Error(localize('mustConfigureAI', 'You must configure Application Insights to stream logs on Linux Function Apps.'));
} else {
const aiClient: ApplicationInsightsManagementClient = await createAppInsightsClient([context, node.subscription]);
const components = await uiUtils.listAllIterator(aiClient.components.list());
const component: ApplicationInsightsComponent | undefined = components.find(c => c.instrumentationKey === aiKey);
const component: ApplicationInsightsComponent | undefined = components.find(c => c.connectionString === aiKey || c.instrumentationKey === aiKey);
if (!component) {
throw new Error(localize('failedToFindAI', 'Failed to find application insights component.'));
} else {
Expand Down

0 comments on commit d38ea09

Please sign in to comment.