fix(sentry): use config pipeline for DSN, add MaxRequestBodySize and ProfilesSampleRate

- Heimdall.Web/Program.cs: use Sentry:Dsn from IConfiguration as primary
  source with legacy SENTRY_DSN env var as fallback (no hardcoded DSN)
- Heimdall.Agent/Program.cs: same pattern applied
- Both: add MaxRequestBodySize=Small and ProfilesSampleRate=0.05
  (previously missing); lower TracesSampleRate to 0.05
- appsettings.json: add Sentry:Dsn entry for discoverability

Resolves codify signal: hardcoded-sdk-credentials (C1)
This commit is contained in:
Arnaud Dartois committed 2026-07-28 10:14:34 +00:00
1 parent e8bede3d79
commit edc739dffe
4 files changed
+31 -11

No files matched your search

+10 -6
View File
@@ -4,20 +4,24 @@ using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;
// ── Sentry (GlitchTip) — DSN from env var only ───────────────────
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
var builder = WebApplication.CreateSlimBuilder(args);
// ── Sentry ────────────────────────────────────────────────────────
if (sentryDsn is not null)
// ── Sentry (GlitchTip) — DSN from config pipeline with legacy env var fallback ──
// Primary: Sentry:Dsn from appsettings.json or env var Sentry__Dsn
// Fallback: legacy SENTRY_DSN env var (Docker backward compat)
// Neither set → DSN is null → Sentry SDK no-ops gracefully
var sentryDsn = builder.Configuration["Sentry:Dsn"]
?? Environment.GetEnvironmentVariable("SENTRY_DSN");
if (!string.IsNullOrEmpty(sentryDsn))
{
builder.WebHost.UseSentry(options =>
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
options.TracesSampleRate = 0.05;
options.MaxRequestBodySize = Sentry.Extensibility.RequestSize.Small;
options.ProfilesSampleRate = 0.05;
});
}
+5
View File
@@ -12,5 +12,10 @@
"HeartbeatIntervalSeconds": 30,
"RegistrationMaxRetries": 5,
"Version": "1.0.0"
},
// Sentry/GlitchTip — DSN is read from Sentry:Dsn (or env Sentry__Dsn / legacy SENTRY_DSN)
// When null/empty, Sentry SDK is not initialized (graceful no-op).
"Sentry": {
"Dsn": ""
}
}
+10 -4
View File
@@ -209,16 +209,22 @@ public partial class Program {
internal static void ConfigureServices(WebApplicationBuilder builder)
{
// ── Sentry (GlitchTip) — DSN from env var only ───────────────────
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
if (sentryDsn is not null)
// ── Sentry (GlitchTip) — DSN from config pipeline with legacy env var fallback ──
// Primary: Sentry:Dsn from appsettings.json or env var Sentry__Dsn
// Fallback: legacy SENTRY_DSN env var (Docker backward compat)
// Neither set → DSN is null → Sentry SDK no-ops gracefully
var sentryDsn = builder.Configuration["Sentry:Dsn"]
?? Environment.GetEnvironmentVariable("SENTRY_DSN");
if (!string.IsNullOrEmpty(sentryDsn))
{
builder.WebHost.UseSentry(options =>
{
options.Dsn = sentryDsn;
options.MinimumBreadcrumbLevel = LogLevel.Debug;
options.MinimumEventLevel = LogLevel.Error;
options.TracesSampleRate = 0.1;
options.TracesSampleRate = 0.05;
options.MaxRequestBodySize = Sentry.Extensibility.RequestSize.Small;
options.ProfilesSampleRate = 0.05;
});
}
+6 -1
View File
@@ -6,5 +6,10 @@
}
},
"AllowedHosts": "*",
"ApiBaseUrl": "http://localhost:8080"
"ApiBaseUrl": "http://localhost:8080",
// Sentry/GlitchTip — DSN is read from Sentry:Dsn (or env Sentry__Dsn / legacy SENTRY_DSN)
// When null/empty, Sentry SDK is not initialized (graceful no-op).
"Sentry": {
"Dsn": ""
}
}