Skip to content

Commit

Permalink
feat: .net9 support (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
prom3theu5 authored Nov 14, 2024
1 parent 4974a8d commit 687e717
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:

- name: Setup .Net SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Run clean
run: eng/ci.sh clean
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

- name: Setup .Net SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Run clean
run: eng/ci.sh clean
Expand Down
72 changes: 41 additions & 31 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
<Project>
<ItemGroup>
<PackageVersion Include="Aspirant.Hosting" Version="0.0.4" />
<PackageVersion Include="Aspire.Hosting.AppHost" Version="8.1.0" />
<PackageVersion Include="Aspire.Hosting.Seq" Version="8.1.0" />
<PackageVersion Include="Aspire.Seq" Version="8.1.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.7.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="8.1.0" />
<PackageVersion Include="MinVer" Version="5.0.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageVersion Include="Serilog" Version="4.0.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageVersion Include="Serilog.Enrichers.Context" Version="4.6.5" />
<PackageVersion Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageVersion Include="Serilog.Enrichers.Process" Version="3.0.0" />
<PackageVersion Include="Serilog.Enrichers.Span" Version="3.1.0" />
<PackageVersion Include="Serilog.Exceptions" Version="8.4.0" />
<PackageVersion Include="Serilog.Exceptions.EntityFrameworkCore" Version="8.4.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.OpenTelemetry" Version="4.0.0" />
<PackageVersion Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="8.1.0" />
<PackageVersion Include="Aspire.Npgsql" Version="8.1.0" />
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.1" />
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="8.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Serilog.Sinks.Spectre" Version="0.5.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageVersion Include="Aspire.Hosting.AppHost" Version="8.2.2" />
<PackageVersion Include="Aspire.Hosting.Seq" Version="8.2.2" />
<PackageVersion Include="Aspire.Seq" Version="8.2.2" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="8.2.2" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="8.2.2" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0' ">
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageVersion Include="Aspire.Hosting.Seq" Version="9.0.0" />
<PackageVersion Include="Aspire.Seq" Version="9.0.0" />
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
<PackageVersion Include="MinVer" Version="6.0.0" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageVersion Include="Serilog" Version="4.1.0" />
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageVersion Include="Serilog.Enrichers.Context" Version="4.6.5" />
<PackageVersion Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageVersion Include="Serilog.Enrichers.Process" Version="3.0.0" />
<PackageVersion Include="Serilog.Enrichers.Span" Version="3.1.0" />
<PackageVersion Include="Serilog.Exceptions" Version="8.4.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Sinks.OpenTelemetry" Version="4.1.1" />
<PackageVersion Include="Serilog.Sinks.Seq" Version="8.0.0" />
<PackageVersion Include="Aspire.Npgsql" Version="8.1.0" />
<PackageVersion Include="AspNetCore.HealthChecks.NpgSql" Version="8.0.2" />
<PackageVersion Include="AspNetCore.HealthChecks.Uris" Version="8.0.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Serilog.Sinks.Spectre" Version="0.5.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace SimCube.Aspire.Hosting.Features.HealthChecks;

public class HealthCheckAnnotation(Func<IResource, CancellationToken, Task<IHealthCheck?>> healthCheckFactory) : IResourceAnnotation
{
/// <summary>
/// A factory that creates a health check from a resource
/// </summary>
public Func<IResource, CancellationToken, Task<IHealthCheck?>> HealthCheckFactory { get; } = healthCheckFactory;

/// <summary>
/// Create a <see cref="HealthCheckAnnotation"/> from
/// </summary>
/// <param name="connectionStringFactory"></param>
/// <returns>A new <see cref="HealthCheckAnnotation"/>.</returns>
public static HealthCheckAnnotation Create(Func<string, IHealthCheck> connectionStringFactory) =>
new(async (resource, token) =>
{
if (resource is not IResourceWithConnectionString c)
{
return null;
}

return await c.GetConnectionStringAsync(token) is not { } cs ? null : connectionStringFactory(cs);
});
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using HealthCheckAnnotation = SimCube.Aspire.Hosting.Features.HealthChecks.HealthCheckAnnotation;

namespace SimCube.Aspire.Hosting.Features.Postgres;

public static class PostgreSqlHealthCheckExtensions
Expand Down
23 changes: 1 addition & 22 deletions src/SimCube.Aspire.Hosting/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
global using System.Collections.Concurrent;
global using System.Runtime.ExceptionServices;
global using Aspirant.Hosting;
global using Aspire.Hosting;
global using Aspire.Hosting.ApplicationModel;
global using Aspire.Hosting.Lifecycle;
global using HealthChecks.NpgSql;
global using HealthChecks.Uris;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Diagnostics.HealthChecks;
global using Microsoft.Extensions.Hosting;
global using Microsoft.Extensions.Logging;
global using OpenTelemetry;
global using OpenTelemetry.Metrics;
global using OpenTelemetry.Trace;
global using Polly;
global using Polly.Retry;
global using Serilog;
global using Serilog.Enrichers.Span;
global using Serilog.Exceptions;
global using Serilog.Exceptions.Core;
global using Serilog.Exceptions.EntityFrameworkCore.Destructurers;
global using Serilog.Sinks.OpenTelemetry;
global using SimCube.Aspire.Features.Otlp;
global using SimCube.Aspire.Features.Seq;
global using SimCube.Aspire.Hosting.Features.HealthChecks;
global using SimCube.Aspire.Features.Seq;
5 changes: 2 additions & 3 deletions src/SimCube.Aspire.Hosting/SimCube.Aspire.Hosting.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net9.0;net8.0;</TargetFrameworks>
<OutputType>Library</OutputType>
</PropertyGroup>

Expand Down Expand Up @@ -31,8 +31,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Aspirant.Hosting" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
<PackageReference Include="Aspire.Hosting.Seq" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" />
Expand Down
18 changes: 11 additions & 7 deletions src/SimCube.Aspire/Features/Otlp/OtlpServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public static LoggerConfiguration GetLoggerConfiguration(this IConfiguration con
.Enrich.WithThreadId()
.Enrich.WithSpan()
.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder()
.WithDefaultDestructurers()
.WithDestructurers([ new DbUpdateExceptionDestructurer() ]))
.WithDefaultDestructurers())
.Enrich.WithProperty(nameof(OtlpLiterals.ServiceName), configuration[OtlpLiterals.ServiceName])
.WriteTo.Spectre(outputTemplate: consoleOutputFormat);

if (!string.IsNullOrEmpty(configuration[OtlpLiterals.Endpoint]))
var otlpEndpoint = configuration.GetValue(OtlpLiterals.Endpoint, string.Empty);

if (!string.IsNullOrEmpty(otlpEndpoint))
{
config = config.WriteTo.OpenTelemetry(options =>
{
Expand All @@ -54,9 +55,12 @@ public static LoggerConfiguration GetLoggerConfiguration(this IConfiguration con
});
}

if (!string.IsNullOrEmpty(configuration[SeqLiterals.SeqEndpoint]))
var seqEndpoint = configuration.GetValue(SeqLiterals.SeqEndpoint, string.Empty);

if (!string.IsNullOrEmpty(seqEndpoint))
{
config = config.WriteTo.Seq(configuration[SeqLiterals.SeqEndpoint]);
var apiKey = configuration.GetValue(SeqLiterals.SeqApiKey, string.Empty);
config = config.WriteTo.Seq(serverUrl: seqEndpoint, apiKey: apiKey);
}

return config;
Expand All @@ -73,7 +77,7 @@ public static void MapDefaultEndpoints(this WebApplication app)

app.MapHealthChecks("/alive", new()
{
Predicate = r => r.Tags.Contains("live")
Predicate = r => r.Tags.Contains("live"),
});
}

Expand Down Expand Up @@ -110,7 +114,7 @@ private static void ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
.WithTracing(tracing =>
{
tracing.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation(options => options.FilterHttpRequestMessage = request =>
.AddHttpClientInstrumentation(options => options.FilterHttpRequestMessage = (HttpRequestMessage request) =>
!request.RequestUri?.AbsoluteUri.Contains(builder.Configuration[OtlpLiterals.Endpoint],
StringComparison.Ordinal) ?? true);
});
Expand Down
1 change: 1 addition & 0 deletions src/SimCube.Aspire/Features/Seq/SeqLiterals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ namespace SimCube.Aspire.Features.Seq;
public static class SeqLiterals
{
public const string SeqEndpoint = "OTLP_SEQ_ENDPOINT";
public const string SeqApiKey = "OTLP_SEQ_API_KEY";
}
5 changes: 0 additions & 5 deletions src/SimCube.Aspire/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Diagnostics.HealthChecks;
Expand All @@ -8,14 +7,10 @@
global using OpenTelemetry;
global using OpenTelemetry.Metrics;
global using OpenTelemetry.Trace;
global using Polly;
global using Polly.Retry;
global using Serilog;
global using Serilog.Enrichers.Span;
global using Serilog.Exceptions;
global using Serilog.Exceptions.Core;
global using Serilog.Exceptions.EntityFrameworkCore.Destructurers;
global using Serilog.Sinks.OpenTelemetry;
global using Serilog.Sinks.Spectre;
global using SimCube.Aspire.Features.Otlp;
global using SimCube.Aspire.Features.Seq;
3 changes: 1 addition & 2 deletions src/SimCube.Aspire/SimCube.Aspire.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<OutputType>Library</OutputType>
</PropertyGroup>

Expand Down Expand Up @@ -49,7 +49,6 @@
<PackageReference Include="Serilog.Enrichers.Process"/>
<PackageReference Include="Serilog.Enrichers.Span"/>
<PackageReference Include="Serilog.Exceptions"/>
<PackageReference Include="Serilog.Exceptions.EntityFrameworkCore"/>
<PackageReference Include="Serilog.Sinks.Console"/>
<PackageReference Include="Serilog.Sinks.OpenTelemetry"/>
<PackageReference Include="Serilog.Sinks.Seq" />
Expand Down

0 comments on commit 687e717

Please sign in to comment.