Refactor Sentry initialization in Program.cs to conditionally set DSN based on configuration; enhance DiscordService to create a service scope for command module registration.
This commit is contained in:
BIN
src/.DS_Store
vendored
BIN
src/.DS_Store
vendored
Binary file not shown.
@@ -42,12 +42,16 @@ builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnC
|
||||
builder.Configuration.AddEnvironmentVariables();
|
||||
builder.Configuration.AddUserSecrets<Program>();
|
||||
|
||||
SentrySdk.Init(options =>
|
||||
// Initialize Sentry conditionally based on DSN availability
|
||||
var sentryDsn = builder.Configuration["Sentry:Dsn"];
|
||||
if (!string.IsNullOrWhiteSpace(sentryDsn))
|
||||
{
|
||||
SentrySdk.Init(options =>
|
||||
{
|
||||
// A Sentry Data Source Name (DSN) is required.
|
||||
// See https://docs.sentry.io/concepts/key-terms/dsn-explainer/
|
||||
// You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
|
||||
options.Dsn = builder.Configuration["Sentry:Dsn"];
|
||||
options.Dsn = sentryDsn;
|
||||
|
||||
// When debug is enabled, the Sentry client will emit detailed debugging information to the console.
|
||||
// This might be helpful, or might interfere with the normal operation of your application.
|
||||
@@ -68,7 +72,8 @@ SentrySdk.Init(options =>
|
||||
options.TracesSampleRate = 0.1;
|
||||
|
||||
options.Environment = builder.Environment.EnvironmentName;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddCheck("self", () => HealthCheckResult.Healthy(), ["api"]);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Discord;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.Net;
|
||||
using Discord.WebSocket;
|
||||
@@ -64,7 +64,11 @@ namespace Managing.Infrastructure.Messengers.Discord
|
||||
_client.Log += Log;
|
||||
_commandService.Log += Log;
|
||||
// look for classes implementing ModuleBase to load commands from
|
||||
await _commandService.AddModulesAsync(GetType().Assembly, _services);
|
||||
// Create a service scope to resolve scoped services during command module registration
|
||||
using (var scope = _services.CreateScope())
|
||||
{
|
||||
await _commandService.AddModulesAsync(GetType().Assembly, scope.ServiceProvider);
|
||||
}
|
||||
// log in to Discord, using the provided token
|
||||
await _client.LoginAsync(TokenType.Bot, _settings.Token);
|
||||
// start bot
|
||||
|
||||
Reference in New Issue
Block a user