From edc739dffe47c5ecd3678ce49b3430499b3af04d Mon Sep 17 00:00:00 2001 From: Arnaud Dartois Date: Tue, 28 Jul 2026 10:14:34 +0000 Subject: [PATCH] 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) --- src/Heimdall.Agent/Program.cs | 16 ++++++++++------ src/Heimdall.Agent/appsettings.json | 5 +++++ src/Heimdall.Web/Program.cs | 14 ++++++++++---- src/Heimdall.Web/appsettings.json | 7 ++++++- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Heimdall.Agent/Program.cs b/src/Heimdall.Agent/Program.cs index 5016f39..191aa3a 100644 --- a/src/Heimdall.Agent/Program.cs +++ b/src/Heimdall.Agent/Program.cs @@ -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; }); } diff --git a/src/Heimdall.Agent/appsettings.json b/src/Heimdall.Agent/appsettings.json index 2fd3557..dc7c22c 100644 --- a/src/Heimdall.Agent/appsettings.json +++ b/src/Heimdall.Agent/appsettings.json @@ -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": "" } } diff --git a/src/Heimdall.Web/Program.cs b/src/Heimdall.Web/Program.cs index 4484d5a..344cddd 100644 --- a/src/Heimdall.Web/Program.cs +++ b/src/Heimdall.Web/Program.cs @@ -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; }); } diff --git a/src/Heimdall.Web/appsettings.json b/src/Heimdall.Web/appsettings.json index 82d0a8f..9c61634 100644 --- a/src/Heimdall.Web/appsettings.json +++ b/src/Heimdall.Web/appsettings.json @@ -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": "" + } }