Add Aspire orchestration
Some checks failed
continuous-integration/drone/push Build is failing

Therefore remove previous OpenTelemetry configuration and use the one
provided in service defaults
This commit is contained in:
2024-12-28 17:01:18 +01:00
parent bbac953660
commit 6d23494fd3
15 changed files with 270 additions and 44 deletions

View File

@@ -1,10 +1,7 @@
using Asp.Versioning;
using FluentValidation;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using OpenTelemetry.Trace;
using System.Diagnostics;
using Vegasco.WebApi.Authentication;
using Vegasco.WebApi.Endpoints;
using Vegasco.WebApi.Endpoints.OpenApi;
@@ -20,15 +17,15 @@ public static class DependencyInjectionExtensions
/// <param name="services"></param>
/// <param name="configuration"></param>
/// <param name="environment"></param>
public static void AddWebApiServices(this IServiceCollection services, IConfiguration configuration, IHostEnvironment environment)
public static void AddWebApiServices(this IHostApplicationBuilder builder)
{
services
builder.Services
.AddMiscellaneousServices()
.AddOpenApi()
.AddApiVersioning()
.AddOtel()
.AddAuthenticationAndAuthorization(environment)
.AddDbContext(configuration);
.AddAuthenticationAndAuthorization(builder.Environment);
builder.AddDbContext();
}
private static IServiceCollection AddMiscellaneousServices(this IServiceCollection services)
@@ -98,26 +95,6 @@ public static class DependencyInjectionExtensions
return services;
}
private static IServiceCollection AddOtel(this IServiceCollection services)
{
Activity.DefaultIdFormat = ActivityIdFormat.W3C;
ActivitySource activitySource = new(Constants.AppOtelName);
services.AddSingleton(activitySource);
services.AddOpenTelemetry()
.WithTracing(t =>
{
t.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter()
.AddSource(activitySource.Name);
})
.WithMetrics();
return services;
}
private static IServiceCollection AddAuthenticationAndAuthorization(this IServiceCollection services, IHostEnvironment environment)
{
services.AddOptions<JwtOptions>()
@@ -153,16 +130,9 @@ public static class DependencyInjectionExtensions
return services;
}
private static IServiceCollection AddDbContext(this IServiceCollection services, IConfiguration configuration)
private static IHostApplicationBuilder AddDbContext(this IHostApplicationBuilder builder)
{
services.AddDbContext<ApplicationDbContext>(o =>
{
o.UseNpgsql(configuration.GetConnectionString("Database"), c =>
{
c.EnableRetryOnFailure();
});
});
return services;
builder.AddNpgsqlDbContext<ApplicationDbContext>(Server.AppHost.Shared.Constants.Database.Name);
return builder;
}
}