diff --git a/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts b/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts index 319eefb7..00195e9b 100644 --- a/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts +++ b/src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults.ts @@ -4,6 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import { type RegistryPassword } from "@azure/arm-containerregistry"; +import { type Workspace } from "@azure/arm-operationalinsights"; +import { uiUtils } from "@microsoft/vscode-azext-azureutils"; +import { createOperationalInsightsManagementClient } from "../../utils/azureClients"; import type * as api from "../api/vscode-azurecontainerapps.api"; import { listCredentialsFromRegistry } from "../image/imageSource/containerRegistry/acr/listCredentialsFromRegistry"; import { type DeployWorkspaceProjectContext } from "./DeployWorkspaceProjectContext"; @@ -14,6 +17,8 @@ export async function getDeployWorkspaceProjectResults(context: DeployWorkspaceP const registryCredentials: { username: string, password: RegistryPassword } | undefined = context.registry ? await listCredentialsFromRegistry(context, context.registry) : undefined; + context.logAnalyticsWorkspace ??= await tryGetLogAnalyticsWorkspace(context); + return { resourceGroupId: context.resourceGroup?.id, logAnalyticsWorkspaceId: context.logAnalyticsWorkspace?.id, @@ -26,3 +31,16 @@ export async function getDeployWorkspaceProjectResults(context: DeployWorkspaceP imageName: context.imageName }; } + +export async function tryGetLogAnalyticsWorkspace(context: DeployWorkspaceProjectContext): Promise { + const resourceGroupName = context.resourceGroup?.name; + const logAnalyticsCustomerId = context.managedEnvironment?.appLogsConfiguration?.logAnalyticsConfiguration?.customerId; + + if (!resourceGroupName || !logAnalyticsCustomerId) { + return undefined; + } + + const client = await createOperationalInsightsManagementClient(context); + const workspaces: Workspace[] = await uiUtils.listAllIterator(client.workspaces.listByResourceGroup(resourceGroupName)); + return workspaces.find(w => w.customerId === logAnalyticsCustomerId); +}