diff --git a/MatrixContentFilter/Program.cs b/MatrixContentFilter/Program.cs
index 7eec930..b849131 100644
--- a/MatrixContentFilter/Program.cs
+++ b/MatrixContentFilter/Program.cs
@@ -1,3 +1,4 @@
+using ArcaneLibs.Extensions;
using MatrixContentFilter;
using MatrixContentFilter.Handlers;
using LibMatrix.Services;
@@ -8,63 +9,91 @@ using MatrixContentFilter.Services;
using MatrixContentFilter.Services.AsyncActionQueues;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Diagnostics.Metrics;
using Microsoft.Extensions.Hosting;
+using OpenTelemetry.Metrics;
+using OpenTelemetry.Resources;
+using OpenTelemetry.Trace;
var builder = Host.CreateDefaultBuilder(args);
-builder.ConfigureHostOptions(host => {
- host.ServicesStartConcurrently = true;
- host.ServicesStopConcurrently = true;
- host.ShutdownTimeout = TimeSpan.FromSeconds(5);
-});
-
if (Environment.GetEnvironmentVariable("MATRIXCONTENTFILTER_APPSETTINGS_PATH") is string path)
builder.ConfigureAppConfiguration(x => x.AddJsonFile(path));
var host = builder.ConfigureServices((ctx, services) => {
- var config = new MatrixContentFilterConfiguration(ctx.Configuration);
- services.AddSingleton<MatrixContentFilterConfiguration>(config);
+ var config = new MatrixContentFilterConfiguration(ctx.Configuration);
+ Console.WriteLine("Configuration: {0}", config.ToJson());
+ services.AddSingleton<MatrixContentFilterConfiguration>(config);
+
+ services.AddMetrics(m => m.AddDebugConsole());
+ services.AddSingleton<MatrixContentFilterMetrics>();
+
+ if (config.OpenTelemetry.Enabled) {
+ services.AddOpenTelemetry()
+ .ConfigureResource(resource => resource.AddService("MatrixContentFilter"))
+ .WithTracing(tracing => tracing
+ .AddAspNetCoreInstrumentation()
+ .AddConsoleExporter())
+ .WithMetrics(metrics => metrics
+ .AddAspNetCoreInstrumentation()
+ .AddHttpClientInstrumentation()
+ .AddRuntimeInstrumentation()
+ .AddConsoleExporter());
+ }
+
+ services.AddRoryLibMatrixServices(new() {
+ AppName = "MatrixContentFilter"
+ });
- services.AddRoryLibMatrixServices(new() {
- AppName = "MatrixContentFilter"
- });
+ services.AddMatrixBot().AddCommandHandler().DiscoverAllCommands()
+ .WithInviteHandler<InviteHandler>()
+ .WithCommandResultHandler(CommandResultHandler.HandleAsync);
- services.AddMatrixBot().AddCommandHandler().DiscoverAllCommands()
- .WithInviteHandler(InviteHandler.HandleAsync)
- .WithCommandResultHandler(CommandResultHandler.HandleAsync);
+ services.AddSingleton<InfoCacheService>();
- services.AddSingleton<InfoCacheService>();
+ services.AddSingleton<IContentFilter, ImageFilter>();
+ services.AddSingleton<IContentFilter, VideoFilter>();
+ services.AddSingleton<IContentFilter, PendingInviteLimiter>();
- services.AddSingleton<IContentFilter, ImageFilter>();
+ services.AddSingleton<ConfigurationService>();
+ services.AddSingleton<IHostedService, ConfigurationService>(s => s.GetRequiredService<ConfigurationService>());
+ services.AddSingleton<AsyncMessageQueue>();
+ services.AddSingleton<IHostedService, AsyncMessageQueue>(s => s.GetRequiredService<AsyncMessageQueue>());
- services.AddSingleton<ConfigurationService>();
- services.AddSingleton<IHostedService, ConfigurationService>(s => s.GetRequiredService<ConfigurationService>());
- services.AddSingleton<AsyncMessageQueue>();
- services.AddSingleton<IHostedService, AsyncMessageQueue>(s => s.GetRequiredService<AsyncMessageQueue>());
+ switch (config.AppMode) {
+ case "bot":
+ services.AddHostedService<MatrixContentFilterBot>();
+ if (config.SanityCheck.Enabled)
+ services.AddHostedService<BotModeSanityCheckService>();
+ break;
+ default:
+ throw new NotSupportedException($"Unknown app mode: {config.AppMode}");
+ }
- switch (config.AppMode) {
- case "bot":
- services.AddHostedService<MatrixContentFilterBot>();
- // services.AddHostedService<BotModeSanityCheckService>();
- break;
- default:
- throw new NotSupportedException($"Unknown app mode: {config.AppMode}");
- }
-
- switch (config.AsyncQueueImplementation) {
- case "lifo":
- services.AddSingleton<LiFoAsyncActionQueue>();
- services.AddSingleton<AbstractAsyncActionQueue, LiFoAsyncActionQueue>(s => s.GetRequiredService<LiFoAsyncActionQueue>());
- services.AddSingleton<IHostedService, LiFoAsyncActionQueue>(s => s.GetRequiredService<LiFoAsyncActionQueue>());
- break;
- case "fifo":
- services.AddSingleton<FiFoAsyncActionQueue>();
- services.AddSingleton<AbstractAsyncActionQueue, FiFoAsyncActionQueue>(s => s.GetRequiredService<FiFoAsyncActionQueue>());
- services.AddSingleton<IHostedService, FiFoAsyncActionQueue>(s => s.GetRequiredService<FiFoAsyncActionQueue>());
- break;
- default:
- throw new NotSupportedException($"Unknown async queue implementation: {config.AsyncQueueImplementation}");
- }
-}).UseConsoleLifetime().Build();
+ switch (config.AsyncQueueImplementation) {
+ case "lifo":
+ services.AddSingleton<LiFoAsyncActionQueue>();
+ services.AddSingleton<AbstractAsyncActionQueue, LiFoAsyncActionQueue>(s => s.GetRequiredService<LiFoAsyncActionQueue>());
+ services.AddSingleton<IHostedService, LiFoAsyncActionQueue>(s => s.GetRequiredService<LiFoAsyncActionQueue>());
+ break;
+ case "fifo":
+ services.AddSingleton<FiFoAsyncActionQueue>();
+ services.AddSingleton<AbstractAsyncActionQueue, FiFoAsyncActionQueue>(s => s.GetRequiredService<FiFoAsyncActionQueue>());
+ services.AddSingleton<IHostedService, FiFoAsyncActionQueue>(s => s.GetRequiredService<FiFoAsyncActionQueue>());
+ break;
+ default:
+ throw new NotSupportedException($"Unknown async queue implementation: {config.AsyncQueueImplementation}");
+ }
+ })
+ // .ConfigureLogging((ctx, lb) => {
+ // lb.AddOpenTelemetry(options => {
+ // options
+ // .SetResourceBuilder(
+ // ResourceBuilder.CreateDefault()
+ // .AddService("MatrixContentFilter"))
+ // .AddConsoleExporter();
+ // });
+ // })
+ .UseConsoleLifetime().Build();
await host.RunAsync();
\ No newline at end of file
|