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.AddEnvironmentVariables();
|
||||||
builder.Configuration.AddUserSecrets<Program>();
|
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.
|
// A Sentry Data Source Name (DSN) is required.
|
||||||
// See https://docs.sentry.io/concepts/key-terms/dsn-explainer/
|
// 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.
|
// 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.
|
// 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.
|
// 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.TracesSampleRate = 0.1;
|
||||||
|
|
||||||
options.Environment = builder.Environment.EnvironmentName;
|
options.Environment = builder.Environment.EnvironmentName;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
builder.Services.AddHealthChecks()
|
builder.Services.AddHealthChecks()
|
||||||
.AddCheck("self", () => HealthCheckResult.Healthy(), ["api"]);
|
.AddCheck("self", () => HealthCheckResult.Healthy(), ["api"]);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Net;
|
using Discord.Net;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
@@ -64,7 +64,11 @@ namespace Managing.Infrastructure.Messengers.Discord
|
|||||||
_client.Log += Log;
|
_client.Log += Log;
|
||||||
_commandService.Log += Log;
|
_commandService.Log += Log;
|
||||||
// look for classes implementing ModuleBase to load commands from
|
// 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
|
// log in to Discord, using the provided token
|
||||||
await _client.LoginAsync(TokenType.Bot, _settings.Token);
|
await _client.LoginAsync(TokenType.Bot, _settings.Token);
|
||||||
// start bot
|
// start bot
|
||||||
|
|||||||
Reference in New Issue
Block a user