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

Configure App Insights for Aspire telemetry #15

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ If you want to install the template from local nuget (just to confirm the end to
- execute ```dotnet new install ./bin/release/nventive.Template.1.0.0.nupkg```
- uninstall command : ```dotnet new uninstall nventive.Templates.Aspire```


#### Create new project

- execute ``` dotnet new nv-aspire -n MyApp ```
SulliNV marked this conversation as resolved.
Show resolved Hide resolved
- follow the project readme.md
- follow the project readme.md

#### Parameters
- appInsights
11 changes: 8 additions & 3 deletions template/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
"language": "C#",
"type": "solution"
},

"symbols": {},

"symbols": {
"appInsights": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Include Application Insights integration"
}
},
"postActions": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0-rc.1.24511.1" />
<PackageReference Include="Aspire.Hosting.Azure.ApplicationInsights" Version="9.0.0" Condition="'$(appInsights)' == 'true'" />
<PackageReference Include="Aspire.Hosting.Azure.PostgreSQL" Version="9.0.0-rc.1.24511.1" />
<PackageReference Include="Aspire.Hosting.Azure.Storage" Version="9.0.0-rc.1.24511.1" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" Version="9.0.0-rc.1.24511.1" />
Expand Down
12 changes: 10 additions & 2 deletions template/src/Placeholder.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
.WithExternalHttpEndpoints()
.WithReference(weatherDb);

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

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

#if appInsights
var appInsights = builder.AddAzureApplicationInsights("appinsights");
SulliNV marked this conversation as resolved.
Show resolved Hide resolved

apiService.WithReference(appInsights);
migration.WithReference(appInsights);
webfrontend.WithReference(appInsights);
#endif

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
Loading