Skip to content

Commit b72e5d5

Browse files
martinjtCopilotaaronpowell
authored
Add OpenTelemetry Collector extension/component (#603)
* Added OpenTelemetry Collector component * Fixed DevCertHostingExtensions * Update src/Shared/DevCertHostingExtensions.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Renames * Switch the image syntax * Move to OnBeforeStart for DevCerts * Updated Devcerts code * Updates to devcerts to check for duplicate mounts. * Added an example of the collector usage * Moved to eventing and made all other resources wait for this collector * made the extension methods internal * Added a basic test * Reworked Extensions and added README with examples * Added tests to workflow * Added more tests * object has a null guard earlier so we don't have to force it * Fixing a CA1853 - Dictionary.Remove does its own guard check * Tightening up resource access * Expanding the unit tests * More tests * Adding martinjt as codeowner --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Aaron Powell <me@aaron-powell.com>
1 parent 6657887 commit b72e5d5

25 files changed

+1662
-0
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
Hosting.Ngrok.Tests,
4343
Hosting.NodeJS.Extensions.Tests,
4444
Hosting.Ollama.Tests,
45+
Hosting.OpenTelemetryCollector.Tests,
4546
Hosting.PapercutSmtp.Tests,
4647
Hosting.PostgreSQL.Extensions.Tests,
4748
Hosting.PowerShell.Tests,

CODEOWNERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,9 @@
125125
/tests/CommunityToolkit.Aspire.Hosting.SurrealDb.Tests/ @Odonno
126126
/src/CommunityToolkit.Aspire.SurrealDb/ @Odonno
127127
/tests/CommunityToolkit.Aspire.SurrealDb.Tests/ @Odonno
128+
129+
# CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector
130+
131+
/examples/opentelemetry-collector/ @martinjt
132+
/src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/ @martinjt
133+
/tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests/ @martinjt

CommunityToolkit.Aspire.slnx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@
105105
<Project Path="examples/ollama/CommunityToolkit.Aspire.Hosting.Ollama.ServiceDefaults/CommunityToolkit.Aspire.Hosting.Ollama.ServiceDefaults.csproj" />
106106
<Project Path="examples/ollama/CommunityToolkit.Aspire.Hosting.Ollama.Web/CommunityToolkit.Aspire.Hosting.Ollama.Web.csproj" />
107107
</Folder>
108+
<Folder Name="/examples/opentelemetry-collector/">
109+
<Project Path="examples/opentelemetry-collector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Api/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Api.csproj" />
110+
<Project Path="examples/opentelemetry-collector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.AppHost/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.AppHost.csproj" />
111+
<Project Path="examples/opentelemetry-collector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.ServiceDefaults/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.ServiceDefaults.csproj" />
112+
</Folder>
108113
<Folder Name="/examples/papercut/">
109114
<Project Path="examples/papercut/CommunityToolkit.Aspire.Hosting.PapercutSmtp.AppHost/CommunityToolkit.Aspire.Hosting.PapercutSmtp.AppHost.csproj" />
110115
<Project Path="examples/papercut/CommunityToolkit.Aspire.Hosting.PapercutSmtp.SendMailApi/CommunityToolkit.Aspire.Hosting.PapercutSmtp.SendMailApi.csproj" />
@@ -175,6 +180,7 @@
175180
<Project Path="src/CommunityToolkit.Aspire.Hosting.Ngrok/CommunityToolkit.Aspire.Hosting.Ngrok.csproj" />
176181
<Project Path="src/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.csproj" />
177182
<Project Path="src/CommunityToolkit.Aspire.Hosting.Ollama/CommunityToolkit.Aspire.Hosting.Ollama.csproj" />
183+
<Project Path="src/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.csproj" />
178184
<Project Path="src/CommunityToolkit.Aspire.Hosting.PapercutSmtp/CommunityToolkit.Aspire.Hosting.PapercutSmtp.csproj" />
179185
<Project Path="src/CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions/CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.csproj" />
180186
<Project Path="src/CommunityToolkit.Aspire.Hosting.PowerShell/CommunityToolkit.Aspire.Hosting.PowerShell.csproj" />
@@ -225,6 +231,7 @@
225231
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Ngrok.Tests/CommunityToolkit.Aspire.Hosting.Ngrok.Tests.csproj" />
226232
<Project Path="tests/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests/CommunityToolkit.Aspire.Hosting.NodeJS.Extensions.Tests.csproj" />
227233
<Project Path="tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests/CommunityToolkit.Aspire.Hosting.Ollama.Tests.csproj" />
234+
<Project Path="tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests/CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Tests.csproj" />
228235
<Project Path="tests/CommunityToolkit.Aspire.Hosting.PapercutSmtp.Tests/CommunityToolkit.Aspire.Hosting.PapercutSmtp.Tests.csproj" />
229236
<Project Path="tests/CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.Tests/CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions.Tests.csproj" />
230237
<Project Path="tests/CommunityToolkit.Aspire.Hosting.PowerShell.Tests/CommunityToolkit.Aspire.Hosting.PowerShell.Tests.csproj" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<Nullable>enable</Nullable>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.ServiceDefaults\CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.ServiceDefaults.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Api_HostAddress = http://localhost:5121
2+
3+
GET {{CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Api_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
3+
builder.AddServiceDefaults();
4+
5+
var app = builder.Build();
6+
7+
var summaries = new[]
8+
{
9+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
10+
};
11+
12+
app.MapGet("/weatherforecast", () =>
13+
{
14+
var forecast = Enumerable.Range(1, 5).Select(index =>
15+
new WeatherForecast
16+
(
17+
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
18+
Random.Shared.Next(-20, 55),
19+
summaries[Random.Shared.Next(summaries.Length)]
20+
))
21+
.ToArray();
22+
return forecast;
23+
})
24+
.WithName("GetWeatherForecast");
25+
26+
app.Run();
27+
28+
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
29+
{
30+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": false,
8+
"applicationUrl": "http://localhost:5121",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
},
13+
"https": {
14+
"commandName": "Project",
15+
"dotnetRunMessages": true,
16+
"launchBrowser": false,
17+
"applicationUrl": "https://localhost:7262;http://localhost:5121",
18+
"environmentVariables": {
19+
"ASPNETCORE_ENVIRONMENT": "Development"
20+
}
21+
}
22+
}
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
builder.AddProject<Projects.CommunityToolkit_Aspire_Hosting_OpenTelemetryCollector_Api>("api");
4+
5+
builder.AddOpenTelemetryCollector("opentelemetry-collector")
6+
.WithAppForwarding()
7+
.WithConfig("./config.yaml");
8+
9+
builder.Build().Run();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<UserSecretsId>f0af42ab-ea83-435c-9273-89269ca78d75</UserSecretsId>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Aspire.Hosting.AppHost"/>
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Api\CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.Api.csproj" />
18+
<ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector\CommunityToolkit.Aspire.Hosting.OpenTelemetryCollector.csproj" IsAspireProjectResource="false" />
19+
</ItemGroup>
20+
21+
</Project>

0 commit comments

Comments
 (0)