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

Fix AppInsights dev time provisioning #2053

Merged
merged 1 commit into from
Feb 3, 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
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageVersion Include="Azure.Storage.Queues" Version="12.17.1" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.37.1" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.1" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.1.0" />
<!-- Azure Management SDK for .NET dependencies -->
<PackageVersion Include="Azure.ResourceManager.CosmosDB" Version="1.4.0-beta.5" />
<PackageVersion Include="Azure.ResourceManager.KeyVault" Version="1.2.0" />
Expand All @@ -24,6 +25,7 @@
<PackageVersion Include="Azure.ResourceManager.AppConfiguration" Version="1.1.0" />
<PackageVersion Include="Azure.ResourceManager.Sql" Version="1.2.0" />
<PackageVersion Include="Azure.ResourceManager.ApplicationInsights" Version="1.0.0-beta.4" />
<PackageVersion Include="Azure.ResourceManager.OperationalInsights" Version="1.2.0" />
<!-- ASP.NET Core dependencies -->
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="$(MicrosoftAspNetCoreOpenApiPackageVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.OutputCaching.StackExchangeRedis" Version="$(MicrosoftAspNetCoreOutputCachingStackExchangeRedisPackageVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="Azure.ResourceManager.Storage" />
<PackageReference Include="Azure.ResourceManager.Sql" />
<PackageReference Include="Azure.ResourceManager.ApplicationInsights" />
<PackageReference Include="Azure.ResourceManager.OperationalInsights" />
<Compile Include="$(SharedDir)ValueStopwatch\*.cs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

using System.Diagnostics;
using Aspire.Hosting.ApplicationModel;
using Azure.ResourceManager.ApplicationInsights;
using Azure;
using Azure.ResourceManager.ApplicationInsights;
using Azure.ResourceManager.OperationalInsights;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -38,6 +39,17 @@ public override async Task GetOrCreateResourceAsync(AzureApplicationInsightsReso

if (applicationInsightsResource is null)
{
var logAnalytics = new OperationalInsightsWorkspaceData(context.Location);
logAnalytics.Tags.Add(AzureProvisioner.AspireResourceNameTag, resource.Name);

var workspaceName = Guid.NewGuid().ToString().Replace("-", string.Empty)[0..20];

logger.LogInformation("Creating Log Analytics Workspace {workspaceName} in {location}...", workspaceName, context.Location);
var sw = Stopwatch.StartNew();
var workspaceOp = await context.ResourceGroup.GetOperationalInsightsWorkspaces().CreateOrUpdateAsync(WaitUntil.Completed, workspaceName, logAnalytics, cancellationToken).ConfigureAwait(false);
sw.Stop();
logger.LogInformation("Log Analytics Workspace {workspaceName} created in {elapsed}", workspaceOp.Value.Data.Name, TimeSpan.FromSeconds(10));

var applicationInsightsName = Guid.NewGuid().ToString().Replace("-", string.Empty)[0..20];

// We could model application insights as a child resource of a log analytics workspace, but instead,
Expand All @@ -47,11 +59,11 @@ public override async Task GetOrCreateResourceAsync(AzureApplicationInsightsReso

var applicationInsightsCreateOrUpdateContent = new ApplicationInsightsComponentData(context.Location, "web")
{
WorkspaceResourceId = ""// context.LogAnalyticsWorkspace.Id
WorkspaceResourceId = workspaceOp.Value.Id
};
applicationInsightsCreateOrUpdateContent.Tags.Add(AzureProvisioner.AspireResourceNameTag, resource.Name);

var sw = Stopwatch.StartNew();
sw.Restart();
var operation = await context.ResourceGroup.GetApplicationInsightsComponents().CreateOrUpdateAsync(WaitUntil.Completed, applicationInsightsName, applicationInsightsCreateOrUpdateContent, cancellationToken).ConfigureAwait(false);
applicationInsightsResource = operation.Value;
sw.Stop();
Expand Down