Skip to content

Conversation

@ShilpiRach
Copy link
Contributor

@ShilpiRach ShilpiRach commented Oct 14, 2025

Description

The changes in this PR is for the following change:

Adding support to enable Application Insights for App Service

  • Added properties to AzureAppServiceEnvironmentResource to track if App Insights is enabled (default is false) and to track location for provisioning App Insights.

    • This is needed because the available regions for Application Insights resource is very different from the available regions for App Service.
  • Added 3 overloads for WithAzureApplicationInsights

    • WithAzureApplicationInsights (string? location)
      • location is optional, if not specified we provision app insights resource in ResourceGroup location
    • WithAzureApplicationInsights (IResouceBuilder<ParameterResource>)
      • This is to allow customers to choose App Insights location during deployment.
  • WithAzureApplicationInsights (IResouceBuilder<AzureApplicationInsightsResource>)

    • This is to allow customers to choose an existing App Insights resource.
  • Also added support WithAzureApplicationInsights for app service

    • This allows an app service to disable application insights

Testing

Ran azd up and aspire deploy for the 3 scenarios:

  • WithAzureApplicationInsights() - Validated that app insights resource is provisioned in the resource group location (only bicep generation).
  • WithAzureApplicationInsights(location) - Validated that app insights resource is provisioned in the specified location.
  • WithAzureApplicationInsights(locationParam) - Validated that during deployment, we get prompt for specifying app Insights location and app insights resource is provisioned in the specified location.
image image
  • WithAzureApplicationInsights(appInsightsResource) - Validated that existing app insights resource is referenced by the app services
image image

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

@github-actions
Copy link
Contributor

github-actions bot commented Oct 14, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11998

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11998"

@github-actions github-actions bot added the area-integrations Issues pertaining to Aspire Integrations packages label Oct 14, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 14, 2025
@ShilpiRach ShilpiRach changed the title [TESTING] Enabled Application Insights by default [TESTING] Added support for enabling Application Insights for App Service Oct 17, 2025
@ShilpiRach ShilpiRach changed the title [TESTING] Added support for enabling Application Insights for App Service Added support for enabling Application Insights for App Service Oct 17, 2025
@ShilpiRach ShilpiRach changed the title Added support for enabling Application Insights for App Service [Testing] Added support for enabling Application Insights for App Service Oct 17, 2025
@ShilpiRach ShilpiRach changed the title [Testing] Added support for enabling Application Insights for App Service Added support for enabling Application Insights for App Service Oct 17, 2025
@ShilpiRach ShilpiRach marked this pull request as ready for review October 17, 2025 20:11
Copilot AI review requested due to automatic review settings October 17, 2025 20:11
@ShilpiRach ShilpiRach requested a review from eerhardt as a code owner October 17, 2025 20:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for enabling Application Insights in Azure App Service environments and surfaces the resulting App Service URL during deployment.

  • Introduces environment properties and extension methods to enable and configure Application Insights (string or parameter-based location).
  • Generates Bicep outputs and infrastructure resources (Log Analytics + Application Insights) and adds related app settings.
  • Updates deployment utilities to construct and print the App Service URL.

Reviewed Changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
AzureAppServiceTests.AzureAppServiceEnvironmentCanReferenceExistingAppServicePlan.verified.bicep Adds unique string output used for App Service hostname construction.
AzureAppServiceTests.AddContainerAppEnvironmentAddsEnvironmentResource.verified.bicep Same unique string output added for hostname logic.
AzureAppServiceTests.AddAppServiceWithApplicationInsightsLocationParam.verified.json Adds manifest params including Application Insights location parameter.
AzureAppServiceTests.AddAppServiceWithApplicationInsightsLocationParam.verified.bicep Generates resources (Web App, Log Analytics, App Insights) using parameter-based location.
AzureAppServiceTests.AddAppServiceWithApplicationInsightsLocation.verified.json Adds manifest without explicit App Insights param (fixed location).
AzureAppServiceTests.AddAppServiceWithApplicationInsightsLocation.verified.bicep Generates resources with explicit string location for App Insights.
AzureAppServiceTests.AddAppServiceWithApplicationInsightsDefaultLocation.verified.json Manifest for default (resource group) location scenario.
AzureAppServiceTests.AddAppServiceWithApplicationInsightsDefaultLocation.verified.bicep Generates resources with App Insights in resource group location.
AzureAppServiceTests.AddAppServiceEnvironmentWithoutDashboardAddsEnvironmentResource.verified.bicep Adds unique string output for hostname when dashboard disabled.
AzureAppServiceTests.cs Adds three new tests covering string, default, and parameter-based App Insights location.
AzureEnvironmentResource.cs Adds logic to derive and print App Service endpoint URL using unique string output.
AzureAppServiceWebsiteContext.cs Adds creation of Log Analytics workspace, Application Insights component, and related app settings.
AzureAppServiceEnvironmentResource.cs Adds properties controlling Application Insights enablement and location configuration.
AzureAppServiceEnvironmentExtensions.cs Adds two public extension methods to enable Application Insights (string or parameter).
Aspire.Hosting.Azure.AppService.csproj Adds project reference to Application Insights provisioning assembly.

Comment on lines +174 to +181
/// <summary>
/// Configures whether Azure Application Insights should be enabled for the Azure App Service.
/// </summary>
/// <param name="builder">The AzureAppServiceEnvironmentResource to configure.</param>
/// <param name="applicationInsightsLocation">The location for Application Insights.</param>
/// <returns><see cref="IResourceBuilder{T}"/></returns>
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithAzureApplicationInsights(this IResourceBuilder<AzureAppServiceEnvironmentResource> builder, string? applicationInsightsLocation = null)
{
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These public extension methods lack remarks and usage examples required by the XML documentation standards; add a section explaining default behavior (resource group location when null), precedence between string and parameter overloads, and an showing enabling Application Insights with explicit and parameter-based locations.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +189 to +196
/// <summary>
/// Configures whether Azure Application Insights should be enabled for the Azure App Service.
/// </summary>
/// <param name="builder">The AzureAppServiceEnvironmentResource to configure.</param>
/// <param name="applicationInsightsLocation">The location parameter for Application Insights.</param>
/// <returns><see cref="IResourceBuilder{T}"/></returns>
public static IResourceBuilder<AzureAppServiceEnvironmentResource> WithAzureApplicationInsights(this IResourceBuilder<AzureAppServiceEnvironmentResource> builder, IResourceBuilder<ParameterResource> applicationInsightsLocation)
{
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These public extension methods lack remarks and usage examples required by the XML documentation standards; add a section explaining default behavior (resource group location when null), precedence between string and parameter overloads, and an showing enabling Application Insights with explicit and parameter-based locations.

Copilot generated this review using guidance from repository custom instructions.

await ExecuteBeforeStartHooksAsync(app, default);

var model = app.Services.GetRequiredService<DistributedApplicationModel>();
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable model is retrieved but never used in these three test methods; remove the unused assignments to keep tests concise.

Copilot uses AI. Check for mistakes.
@davidfowl
Copy link
Member

You need to be able to customize this.

@ShilpiRach
Copy link
Contributor Author

You need to be able to customize this.

Added support for that using ConfigureInfrastructure - AppInsights is now provisioned as an infra resource

Comment on lines 552 to 557
var hostName = $"{computeResource.Name.ToLowerInvariant()}.{webSiteSuffix}";
if (hostName.Length > 60)
{
hostName = hostName.Substring(0, 60);
}
var endpoint = $"https://{hostName}.azurewebsites.net";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 things here.

  1. This needs a - in between, not a ..
  2. In a follow up, we could use this method.
    ReferenceExpression IComputeEnvironmentResource.GetHostAddressExpression(EndpointReference endpointReference)
    {
    var resource = endpointReference.Resource;
    return ReferenceExpression.Create($"{resource.Name.ToLowerInvariant()}-{WebSiteSuffix}.azurewebsites.net");
    }

    This scenario is exactly what that method is intended for - given an EndpointReference to a compute resource, get its HostAddress for the given environment.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@eerhardt eerhardt enabled auto-merge (squash) October 24, 2025 19:32
@eerhardt eerhardt merged commit 9ff11a5 into dotnet:main Oct 24, 2025
895 of 901 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 13.0 milestone Oct 24, 2025
radical pushed a commit that referenced this pull request Oct 29, 2025
## Description

The changes in this PR is for the following change:
#### Adding support to enable Application Insights for App Service
- Added properties to AzureAppServiceEnvironmentResource to track if App Insights is enabled (default is false) and to track location for provisioning App Insights.
  - This is needed because the available regions for Application Insights resource is very different from the available regions for App Service.
- Added 3 overloads for `WithAzureApplicationInsights`
  -  `WithAzureApplicationInsights (string? location)`
     - `location` is optional, if not specified we provision app insights resource in ResourceGroup location
  - `WithAzureApplicationInsights (IResouceBuilder<ParameterResource>)`
     - This is to allow customers to choose App Insights location during deployment.
 -  `WithAzureApplicationInsights (IResouceBuilder<AzureApplicationInsightsResource>)`
     - This is to allow customers to choose an existing App Insights resource.

- Also added support WithAzureApplicationInsights for app service
    - This allows an app service to disable application insights

* Enabled Application Insights by default

* Build fixes

* Added override for App Insights location

* Printing app service uri

* Added resource parameter for app insights location and tests

* Fixed ParameterResource for app insights location

* Changed method signatures for enabling app insights

* Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs

Co-authored-by: Copilot <[email protected]>

* Update tests/Aspire.Hosting.Azure.Tests/AzureAppServiceTests.cs

Co-authored-by: Copilot <[email protected]>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <[email protected]>

* Update src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs

Co-authored-by: Copilot <[email protected]>

* Update tests/Aspire.Hosting.Azure.Tests/AzureAppServiceTests.cs

Co-authored-by: Copilot <[email protected]>

* Reverting the change to print app service urls

* Moved AI resource to environment

* Printing endpoints of compute resources

* Added support to add existing application insights

* Added tests

* Remove support to disable AppInsights at website level

* Switched to use ApplicationInsightsResource directly in AzureAppServiceEnvironment

* nit fix

* Update src/Aspire.Hosting.Azure/AzureEnvironmentResource.cs

Co-authored-by: Eric Erhardt <[email protected]>

---------

Co-authored-by: Shilpi Rachna <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Eric Erhardt <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-integrations Issues pertaining to Aspire Integrations packages community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants