add open telemetry and refactor setup

This commit is contained in:
2024-01-23 13:10:16 +01:00
parent 8abe228d89
commit 65132fc7c6
5 changed files with 260 additions and 19 deletions
+10 -19
View File
@@ -11,6 +11,9 @@ using Kemkas.Web.Services.Identity;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Identity.UI.Services;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;
var builder = WebApplication.CreateBuilder(args);
@@ -34,25 +37,7 @@ builder.Services.AddSingleton<IEmailSender, MailgunEmailSender>();
builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddAuthentication()
.AddGoogle(options =>
{
var section = builder.Configuration.GetSection("Authentication:Google");
options.ClientId = section["ClientId"];
options.ClientSecret = section["ClientSecret"];
})
.AddFacebook(options =>
{
var section = builder.Configuration.GetSection("Authentication:Facebook");
options.ClientId = section["ClientId"];
options.ClientSecret = section["ClientSecret"];
})
.AddDiscord(options =>
{
var section = builder.Configuration.GetSection("Authentication:Discord");
options.ClientId = section["ClientId"];
options.ClientSecret = section["ClientSecret"];
});
builder.AddAuth();
builder.Services.AddControllersWithViews().AddJsonOptions(options =>
{
@@ -62,6 +47,10 @@ builder.Services.AddControllersWithViews().AddJsonOptions(options =>
});
builder.Services.AddRazorPages();
builder.AddOpenTelemetry();
builder.Services.AddHealthChecks();
builder.Services.AddCharacterServices();
var app = builder.Build();
@@ -93,6 +82,8 @@ else
app.UseHsts(); // TODO: check if this should be handled by proxy
}
app.UseHealthChecks("/health");
await using (var scope = app.Services.CreateAsyncScope())
{
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();