From 7c9ae6688e69fe7ea17b112fc047b0f476603db5 Mon Sep 17 00:00:00 2001 From: Shawn Jackson Date: Sat, 18 May 2024 10:26:19 -0700 Subject: [PATCH] CU-8687yhbz5 sentry logging changes --- Core/Resgrid.Config/ExternalErrorConfig.cs | 1 + Core/Resgrid.Framework/Logging.cs | 14 +++++++++++++- Core/Resgrid.Framework/Resgrid.Framework.csproj | 6 ++++-- .../ClaimsPrincipalFactory.cs | 2 ++ .../IdentityUserRepository.cs | 2 ++ .../Stores/IdentityRoleStore.cs | 2 ++ .../Stores/IdentityUserStore.cs | 2 ++ .../Resgrid.Web.Eventing.csproj | 1 + Web/Resgrid.Web.ServicesCore/Program.cs | 10 ++++++++++ .../Resgrid.Web.ServicesCore.csproj | 4 ++-- Web/Resgrid.WebCore/Program.cs | 10 ++++++++++ Web/Resgrid.WebCore/Resgrid.WebCore.csproj | 4 ++-- 12 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Core/Resgrid.Config/ExternalErrorConfig.cs b/Core/Resgrid.Config/ExternalErrorConfig.cs index 5bcb1921..42ba4717 100644 --- a/Core/Resgrid.Config/ExternalErrorConfig.cs +++ b/Core/Resgrid.Config/ExternalErrorConfig.cs @@ -22,6 +22,7 @@ public static class ExternalErrorConfig public static string ExternalErrorServiceUrlForInternalApi = ""; public static string ExternalErrorServiceUrlForInternalWorker = ""; public static double SentryPerfSampleRate = 0.4; + public static double SentryProfilingSampleRate = 0; #endregion Sentry Settings #region Application Insights Settings diff --git a/Core/Resgrid.Framework/Logging.cs b/Core/Resgrid.Framework/Logging.cs index b6f95fa5..f1ae54ae 100644 --- a/Core/Resgrid.Framework/Logging.cs +++ b/Core/Resgrid.Framework/Logging.cs @@ -1,5 +1,7 @@ -using Resgrid.Config; +using Microsoft.Extensions.Options; +using Resgrid.Config; using Sentry; +using Sentry.Profiling; using Serilog; using Serilog.Core; using Serilog.Events; @@ -10,6 +12,7 @@ using System.Net.Mail; using System.Reflection; using System.Runtime.CompilerServices; +using static NodaTime.TimeZones.ZoneEqualityComparer; namespace Resgrid.Framework { @@ -39,9 +42,18 @@ public static void Initialize(string key) o.Dsn = dsn; o.AttachStacktrace = true; o.SendDefaultPii = true; + o.AutoSessionTracking = true; o.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate; o.Environment = ExternalErrorConfig.Environment; o.Release = Assembly.GetEntryAssembly().GetName().Version.ToString(); + o.ProfilesSampleRate = ExternalErrorConfig.SentryProfilingSampleRate; + + // Requires NuGet package: Sentry.Profiling + // Note: By default, the profiler is initialized asynchronously. This can be tuned by passing a desired initialization timeout to the constructor. + o.AddIntegration(new ProfilingIntegration( + // During startup, wait up to 500ms to profile the app startup code. This could make launching the app a bit slower so comment it out if your prefer profiling to start asynchronously + //TimeSpan.FromMilliseconds(500) + )); }).CreateLogger(); } else if (SystemBehaviorConfig.ErrorLoggerType == ErrorLoggerTypes.Elk) diff --git a/Core/Resgrid.Framework/Resgrid.Framework.csproj b/Core/Resgrid.Framework/Resgrid.Framework.csproj index 70fdb22e..a369097f 100644 --- a/Core/Resgrid.Framework/Resgrid.Framework.csproj +++ b/Core/Resgrid.Framework/Resgrid.Framework.csproj @@ -15,8 +15,10 @@ - - + + + + diff --git a/Providers/Resgrid.Providers.Claims/ClaimsPrincipalFactory.cs b/Providers/Resgrid.Providers.Claims/ClaimsPrincipalFactory.cs index 814f5c83..efbb1533 100644 --- a/Providers/Resgrid.Providers.Claims/ClaimsPrincipalFactory.cs +++ b/Providers/Resgrid.Providers.Claims/ClaimsPrincipalFactory.cs @@ -8,6 +8,8 @@ using Resgrid.Model.Identity; using Resgrid.Model.Repositories; using Resgrid.Model.Services; +using IdentityRole = Resgrid.Model.Identity.IdentityRole; +using IdentityUser = Resgrid.Model.Identity.IdentityUser; namespace Resgrid.Providers.Claims { diff --git a/Repositories/Resgrid.Repositories.DataRepository/IdentityUserRepository.cs b/Repositories/Resgrid.Repositories.DataRepository/IdentityUserRepository.cs index 382e4880..1d5529d8 100644 --- a/Repositories/Resgrid.Repositories.DataRepository/IdentityUserRepository.cs +++ b/Repositories/Resgrid.Repositories.DataRepository/IdentityUserRepository.cs @@ -15,6 +15,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using IdentityRole = Resgrid.Model.Identity.IdentityRole; +using IdentityUser = Resgrid.Model.Identity.IdentityUser; namespace Resgrid.Repositories.DataRepository { diff --git a/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityRoleStore.cs b/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityRoleStore.cs index 062ed930..37c3fb85 100644 --- a/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityRoleStore.cs +++ b/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityRoleStore.cs @@ -13,6 +13,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using IdentityRole = Resgrid.Model.Identity.IdentityRole; +using IdentityUser = Resgrid.Model.Identity.IdentityUser; namespace Resgrid.Repositories.DataRepository.Stores { diff --git a/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityUserStore.cs b/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityUserStore.cs index 1616232a..da95f134 100644 --- a/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityUserStore.cs +++ b/Repositories/Resgrid.Repositories.DataRepository/Stores/IdentityUserStore.cs @@ -12,6 +12,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using IdentityRole = Resgrid.Model.Identity.IdentityRole; +using IdentityUser = Resgrid.Model.Identity.IdentityUser; namespace Resgrid.Repositories.DataRepository.Stores { diff --git a/Web/Resgrid.Web.Eventing/Resgrid.Web.Eventing.csproj b/Web/Resgrid.Web.Eventing/Resgrid.Web.Eventing.csproj index 942e1225..0d81563a 100644 --- a/Web/Resgrid.Web.Eventing/Resgrid.Web.Eventing.csproj +++ b/Web/Resgrid.Web.Eventing/Resgrid.Web.Eventing.csproj @@ -44,6 +44,7 @@ + diff --git a/Web/Resgrid.Web.ServicesCore/Program.cs b/Web/Resgrid.Web.ServicesCore/Program.cs index 83e6f12c..002f0235 100644 --- a/Web/Resgrid.Web.ServicesCore/Program.cs +++ b/Web/Resgrid.Web.ServicesCore/Program.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Resgrid.Config; +using Sentry.Profiling; namespace Resgrid.Web.ServicesCore { @@ -40,9 +41,18 @@ public static IHostBuilder CreateHostBuilder(string[] args) => options.Dsn = Config.ExternalErrorConfig.ExternalErrorServiceUrlForApi; options.AttachStacktrace = true; options.SendDefaultPii = true; + options.AutoSessionTracking = true; options.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate; options.Environment = ExternalErrorConfig.Environment; options.Release = Assembly.GetEntryAssembly().GetName().Version.ToString(); + options.ProfilesSampleRate = ExternalErrorConfig.SentryProfilingSampleRate; + + // Requires NuGet package: Sentry.Profiling + // Note: By default, the profiler is initialized asynchronously. This can be tuned by passing a desired initialization timeout to the constructor. + options.AddIntegration(new ProfilingIntegration( + // During startup, wait up to 500ms to profile the app startup code. This could make launching the app a bit slower so comment it out if your prefer profiling to start asynchronously + //TimeSpan.FromMilliseconds(500) + )); options.TracesSampler = samplingContext => { diff --git a/Web/Resgrid.Web.ServicesCore/Resgrid.Web.ServicesCore.csproj b/Web/Resgrid.Web.ServicesCore/Resgrid.Web.ServicesCore.csproj index 69cea90a..28409952 100644 --- a/Web/Resgrid.Web.ServicesCore/Resgrid.Web.ServicesCore.csproj +++ b/Web/Resgrid.Web.ServicesCore/Resgrid.Web.ServicesCore.csproj @@ -64,8 +64,8 @@ - - + + diff --git a/Web/Resgrid.WebCore/Program.cs b/Web/Resgrid.WebCore/Program.cs index a3d133b4..ae8fc779 100644 --- a/Web/Resgrid.WebCore/Program.cs +++ b/Web/Resgrid.WebCore/Program.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Resgrid.Config; +using Sentry.Profiling; namespace Resgrid.Web { @@ -41,7 +42,16 @@ public static IHostBuilder CreateHostBuilder(string[] args) => options.SendDefaultPii = true; options.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate; options.Environment = ExternalErrorConfig.Environment; + options.AutoSessionTracking = true; options.Release = Assembly.GetEntryAssembly().GetName().Version.ToString(); + options.ProfilesSampleRate = ExternalErrorConfig.SentryProfilingSampleRate; + + // Requires NuGet package: Sentry.Profiling + // Note: By default, the profiler is initialized asynchronously. This can be tuned by passing a desired initialization timeout to the constructor. + options.AddIntegration(new ProfilingIntegration( + // During startup, wait up to 500ms to profile the app startup code. This could make launching the app a bit slower so comment it out if your prefer profiling to start asynchronously + //TimeSpan.FromMilliseconds(500) + )); options.TracesSampler = samplingContext => { diff --git a/Web/Resgrid.WebCore/Resgrid.WebCore.csproj b/Web/Resgrid.WebCore/Resgrid.WebCore.csproj index 3b78a19c..56479042 100644 --- a/Web/Resgrid.WebCore/Resgrid.WebCore.csproj +++ b/Web/Resgrid.WebCore/Resgrid.WebCore.csproj @@ -58,8 +58,8 @@ - - + +