Skip to content

Commit

Permalink
feat: configure App Insights for Aspire telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
SulliNV committed Dec 16, 2024
1 parent 295d00a commit b20fe9f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions template/src/Placeholder.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

var weatherDb = builder.ConfigurePostgresDatabase("weather", builder.AddParameter("postgresUsername"), builder.AddParameter("postgresPassword", secret: true));

var appInsights = builder.AddConnectionString("AppInsights", "APPLICATIONINSIGHTS_CONNECTION_STRING");

var apiService = builder.AddProject<Projects.Placeholder_ApiService>("apiservice")
.WithExternalHttpEndpoints()
.WithReference(weatherDb);
.WithReference(weatherDb)
.WithReference(appInsights);

builder.AddProject<Projects.Placeholder_Migration>("migration")
.WithReference(weatherDb);
.WithReference(weatherDb)
.WithReference(appInsights);

builder.AddProject<Projects.Placeholder_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(apiService);
.WithReference(apiService)
.WithReference(appInsights);

builder.Build().Run();
4 changes: 3 additions & 1 deletion template/src/Placeholder.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Azure.Monitor.OpenTelemetry.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -58,7 +59,8 @@ public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicati
// Uncomment the following line to enable gRPC instrumentation (requires the OpenTelemetry.Instrumentation.GrpcNetClient package)
//.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});
})
.UseAzureMonitor();

builder.AddOpenTelemetryExporters();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.2.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0" />

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0" />
Expand Down

0 comments on commit b20fe9f

Please sign in to comment.