From 8d9214bf91bb8fb693d8c88ed4203921301cae51 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 11:58:58 +0200 Subject: [PATCH 01/22] Update packages in EventsHandler project --- EventsHandler/Api/EventsHandler/EventsHandler.csproj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/EventsHandler.csproj b/EventsHandler/Api/EventsHandler/EventsHandler.csproj index fd884302..b75822b0 100644 --- a/EventsHandler/Api/EventsHandler/EventsHandler.csproj +++ b/EventsHandler/Api/EventsHandler/EventsHandler.csproj @@ -32,15 +32,15 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - + From 0194630263ff23089ee184414c553ce0d82f529d Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 11:59:29 +0200 Subject: [PATCH 02/22] Update packages in EventsHandler.IntegrationTests project --- .../EventsHandler.IntegrationTests.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/EventsHandler.IntegrationTests.csproj b/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/EventsHandler.IntegrationTests.csproj index 48268c10..941257fb 100644 --- a/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/EventsHandler.IntegrationTests.csproj +++ b/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/EventsHandler.IntegrationTests.csproj @@ -14,15 +14,15 @@ - + - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 75bc8be162599db770117ba4ea5d3f077d022d8a Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 11:59:58 +0200 Subject: [PATCH 03/22] Update packages in EventsHandler.UnitTests project --- .../EventsHandler.Tests/EventsHandler.UnitTests.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/EventsHandler/Tests/UnitTests/EventsHandler.Tests/EventsHandler.UnitTests.csproj b/EventsHandler/Tests/UnitTests/EventsHandler.Tests/EventsHandler.UnitTests.csproj index c13c3edc..2c0f1389 100644 --- a/EventsHandler/Tests/UnitTests/EventsHandler.Tests/EventsHandler.UnitTests.csproj +++ b/EventsHandler/Tests/UnitTests/EventsHandler.Tests/EventsHandler.UnitTests.csproj @@ -14,15 +14,15 @@ - + - + - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 8cffaa3bd4afcd795c771b470af98a0988cfcf6e Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 12:01:50 +0200 Subject: [PATCH 04/22] Leave TODO token --- EventsHandler/Api/EventsHandler/EventsHandler.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EventsHandler/Api/EventsHandler/EventsHandler.csproj b/EventsHandler/Api/EventsHandler/EventsHandler.csproj index b75822b0..f30b74be 100644 --- a/EventsHandler/Api/EventsHandler/EventsHandler.csproj +++ b/EventsHandler/Api/EventsHandler/EventsHandler.csproj @@ -26,7 +26,7 @@ - + From b2f269f4276268312dcbe92e0588c1c1d1085f03 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 12:21:26 +0200 Subject: [PATCH 05/22] Install Sentry SDK NuGet package --- EventsHandler/Api/EventsHandler/EventsHandler.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/EventsHandler/Api/EventsHandler/EventsHandler.csproj b/EventsHandler/Api/EventsHandler/EventsHandler.csproj index f30b74be..4700bf2a 100644 --- a/EventsHandler/Api/EventsHandler/EventsHandler.csproj +++ b/EventsHandler/Api/EventsHandler/EventsHandler.csproj @@ -39,6 +39,7 @@ + From 7c2cf5dace2e68ddf9d0db050b3f7f379e43cf84 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 15:53:49 +0200 Subject: [PATCH 06/22] Configure SentrySdk in Program.cs --- EventsHandler/Api/EventsHandler/Program.cs | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/EventsHandler/Api/EventsHandler/Program.cs b/EventsHandler/Api/EventsHandler/Program.cs index 37c10367..af174c47 100644 --- a/EventsHandler/Api/EventsHandler/Program.cs +++ b/EventsHandler/Api/EventsHandler/Program.cs @@ -166,9 +166,34 @@ private static WebApplicationBuilder AddNetServices(this WebApplicationBuilder b }); }); - // Swagger UI: Examples + // Swagger UI: Examples (showing custom values of API parameters instead of the default ones) builder.Services.AddSwaggerExamplesFromAssemblyOf(); + // Logging (using "Sentry.io") => Documentation: https://docs.sentry.io/platforms/dotnet/configuration/options/ + SentrySdk.Init(options => + { + // Sentry Data Source Name (DSN) => where to log application events + options.Dsn = "https://4dfba3b56e7a177e0dead03ad82fa9c8@o4506671778168832.ingest.sentry.io/4506772979777536"; + + // Informational messages are the most detailed to log + options.DiagnosticLevel = SentryLevel.Info; + + // Enables Sentry's "Release Health" feature + options.AutoSessionTracking = true; + + // Disables the case that all threads use the same global scope ("true" for client apps, "false" for server apps) + options.IsGlobalModeEnabled = false; + + // The identifier indicating to which or on which platform / system the application is meant to run + options.Distribution = $"{Environment.OSVersion.Platform} | {Environment.OSVersion.VersionString}"; + + // Version of the application ("OMC Web API" in this case) + options.Release = DefaultValues.ApiController.Version; + + // The environment of the application (Prod, Test, Dev, Staging, etc.) + options.Environment = "Production"; + }); + // Application insights: Monitoring builder.Services.AddApplicationInsightsTelemetry(); @@ -286,6 +311,18 @@ private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder b { app.UseSwagger(); app.UseSwaggerUI(); + + SentrySdk.Init(options => + { + // Detailed debugging logs in the console window + options.Debug = true; + + // Debugging messages are the most detailed to log + options.DiagnosticLevel = SentryLevel.Debug; + + // The environment of the application (Prod, Test, Dev, Staging, etc.) + options.Environment = "Development"; + }); } // Production settings From 215d267b408589e9c6acf931743ec859503552ac Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 16:22:28 +0200 Subject: [PATCH 07/22] Remove the old Azure Telemetry --- EventsHandler/Api/EventsHandler/Program.cs | 12 ----------- .../Telemetry/AzureTelemetryService.cs | 21 ------------------- .../Api/EventsHandler/appsettings.json | 5 ----- 3 files changed, 38 deletions(-) delete mode 100644 EventsHandler/Api/EventsHandler/Services/Telemetry/AzureTelemetryService.cs diff --git a/EventsHandler/Api/EventsHandler/Program.cs b/EventsHandler/Api/EventsHandler/Program.cs index af174c47..813e44fb 100644 --- a/EventsHandler/Api/EventsHandler/Program.cs +++ b/EventsHandler/Api/EventsHandler/Program.cs @@ -38,9 +38,7 @@ using EventsHandler.Services.Validation; using EventsHandler.Services.Validation.Interfaces; using EventsHandler.Utilities.Swagger.Examples; -using Microsoft.ApplicationInsights.Extensibility; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.Extensions.Logging.ApplicationInsights; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; using Notify.Models.Responses; @@ -194,15 +192,6 @@ private static WebApplicationBuilder AddNetServices(this WebApplicationBuilder b options.Environment = "Production"; }); - // Application insights: Monitoring - builder.Services.AddApplicationInsightsTelemetry(); - - // Application insights: Logging - builder.Logging.AddApplicationInsights() - .AddFilter( - DefaultValues.Logging.Category, - builder.Configuration.GetApplicationInsightsLogLevel()); - return builder; } @@ -233,7 +222,6 @@ private static WebApplicationBuilder AddCustomServices(this WebApplicationBuilde builder.Services.RegisterClientFactories(); // Feedback and telemetry - builder.Services.AddSingleton(); builder.Services.AddSingleton(); // User Interaction diff --git a/EventsHandler/Api/EventsHandler/Services/Telemetry/AzureTelemetryService.cs b/EventsHandler/Api/EventsHandler/Services/Telemetry/AzureTelemetryService.cs deleted file mode 100644 index 4b5072c9..00000000 --- a/EventsHandler/Api/EventsHandler/Services/Telemetry/AzureTelemetryService.cs +++ /dev/null @@ -1,21 +0,0 @@ -// © 2023, Worth Systems. - -using EventsHandler.Constants; -using Microsoft.ApplicationInsights.Channel; -using Microsoft.ApplicationInsights.Extensibility; - -namespace EventsHandler.Services.Telemetry -{ - /// - internal sealed class AzureTelemetryService : ITelemetryInitializer - { - /// - public void Initialize(ITelemetry telemetry) - { - if (string.IsNullOrEmpty(telemetry.Context.Cloud.RoleName)) - { - telemetry.Context.Cloud.RoleName = DefaultValues.Logging.CloudRoleName; - } - } - } -} \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/appsettings.json b/EventsHandler/Api/EventsHandler/appsettings.json index 358a0283..d3cf0937 100644 --- a/EventsHandler/Api/EventsHandler/appsettings.json +++ b/EventsHandler/Api/EventsHandler/appsettings.json @@ -4,11 +4,6 @@ "Default": "Information", "Microsoft.AspNetCore": "Information", "Microsoft.Hosting.Lifetime": "Information" - }, - "ApplicationInsights": { - "LogLevel": { - "Default": "Information" - } } }, "Encryption": { From 03410883289722092950bf6a657b859e50afff3c Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 16:51:42 +0200 Subject: [PATCH 08/22] Install Sentry.AspNetCore and Sentry.Profiling NuGet packages --- EventsHandler/Api/EventsHandler/EventsHandler.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/EventsHandler/Api/EventsHandler/EventsHandler.csproj b/EventsHandler/Api/EventsHandler/EventsHandler.csproj index 4700bf2a..fc6389b1 100644 --- a/EventsHandler/Api/EventsHandler/EventsHandler.csproj +++ b/EventsHandler/Api/EventsHandler/EventsHandler.csproj @@ -40,6 +40,8 @@ + + From 85c9bf7e1269a6c2e800a98004edc2fca722dee4 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 16:53:01 +0200 Subject: [PATCH 09/22] Remove Azure ApplicationInsight logging service --- EventsHandler/Api/EventsHandler/EventsHandler.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/EventsHandler/Api/EventsHandler/EventsHandler.csproj b/EventsHandler/Api/EventsHandler/EventsHandler.csproj index fc6389b1..d2fc6b38 100644 --- a/EventsHandler/Api/EventsHandler/EventsHandler.csproj +++ b/EventsHandler/Api/EventsHandler/EventsHandler.csproj @@ -28,7 +28,6 @@ - From b061ce0436bbe6d3ba68e355220aa147c5fa62e9 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Wed, 24 Apr 2024 16:53:36 +0200 Subject: [PATCH 10/22] Introduce new extension method for SentryOptions to simplify the configuration --- EventsHandler/Api/EventsHandler/Program.cs | 67 ++++++++++++---------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Program.cs b/EventsHandler/Api/EventsHandler/Program.cs index 813e44fb..0ec42939 100644 --- a/EventsHandler/Api/EventsHandler/Program.cs +++ b/EventsHandler/Api/EventsHandler/Program.cs @@ -167,29 +167,10 @@ private static WebApplicationBuilder AddNetServices(this WebApplicationBuilder b // Swagger UI: Examples (showing custom values of API parameters instead of the default ones) builder.Services.AddSwaggerExamplesFromAssemblyOf(); - // Logging (using "Sentry.io") => Documentation: https://docs.sentry.io/platforms/dotnet/configuration/options/ + // Logging (using "Sentry.io") SentrySdk.Init(options => { - // Sentry Data Source Name (DSN) => where to log application events - options.Dsn = "https://4dfba3b56e7a177e0dead03ad82fa9c8@o4506671778168832.ingest.sentry.io/4506772979777536"; - - // Informational messages are the most detailed to log - options.DiagnosticLevel = SentryLevel.Info; - - // Enables Sentry's "Release Health" feature - options.AutoSessionTracking = true; - - // Disables the case that all threads use the same global scope ("true" for client apps, "false" for server apps) - options.IsGlobalModeEnabled = false; - - // The identifier indicating to which or on which platform / system the application is meant to run - options.Distribution = $"{Environment.OSVersion.Platform} | {Environment.OSVersion.VersionString}"; - - // Version of the application ("OMC Web API" in this case) - options.Release = DefaultValues.ApiController.Version; - - // The environment of the application (Prod, Test, Dev, Staging, etc.) - options.Environment = "Production"; + options.ConfigureSentryOptions(SentryLevel.Info, isDebugEnabled: false); }); return builder; @@ -302,14 +283,7 @@ private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder b SentrySdk.Init(options => { - // Detailed debugging logs in the console window - options.Debug = true; - - // Debugging messages are the most detailed to log - options.DiagnosticLevel = SentryLevel.Debug; - - // The environment of the application (Prod, Test, Dev, Staging, etc.) - options.Environment = "Development"; + options.ConfigureSentryOptions(SentryLevel.Debug, isDebugEnabled: true); }); } @@ -323,5 +297,40 @@ private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder b return app; } + + #region Sentry configuration + /// + /// Configure logging options for Sentry. + /// + /// Source: https://docs.sentry.io/platforms/dotnet/configuration/options/ + /// + /// + private static void ConfigureSentryOptions(this SentryOptions options, SentryLevel diagnosticLevel, bool isDebugEnabled) + { + // Sentry Data Source Name (DSN) => where to log application events + options.Dsn = "https://4dfba3b56e7a177e0dead03ad82fa9c8@o4506671778168832.ingest.sentry.io/4506772979777536"; + + // Informational messages are the most detailed to log + options.DiagnosticLevel = diagnosticLevel; + + // Detailed debugging logs in the console window + options.Debug = isDebugEnabled; + + // Enables Sentry's "Release Health" feature + options.AutoSessionTracking = true; + + // Disables the case that all threads use the same global scope ("true" for client apps, "false" for server apps) + options.IsGlobalModeEnabled = false; + + // The identifier indicating to which or on which platform / system the application is meant to run + options.Distribution = $"{Environment.OSVersion.Platform} | {Environment.OSVersion.VersionString}"; + + // Version of the application ("OMC Web API" in this case) + options.Release = DefaultValues.ApiController.Version; + + // The environment of the application (Prod, Test, Dev, Staging, etc.) + options.Environment = isDebugEnabled ? "Development" : "Production"; + } + #endregion } } \ No newline at end of file From bfde372a07be4b499c254e5c0a1728d3f26a2eb8 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Thu, 25 Apr 2024 08:59:53 +0200 Subject: [PATCH 11/22] Remove plane Sentry to avoid ambiguity --- EventsHandler/Api/EventsHandler/EventsHandler.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/EventsHandler/Api/EventsHandler/EventsHandler.csproj b/EventsHandler/Api/EventsHandler/EventsHandler.csproj index d2fc6b38..e98724f8 100644 --- a/EventsHandler/Api/EventsHandler/EventsHandler.csproj +++ b/EventsHandler/Api/EventsHandler/EventsHandler.csproj @@ -38,7 +38,6 @@ - From e27ff6d7fb0ae6a75c61c8829411a0d4d8ca7d00 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Thu, 25 Apr 2024 13:44:38 +0200 Subject: [PATCH 12/22] Rearrange when Sentry will be registered in Program.cs --- EventsHandler/Api/EventsHandler/Program.cs | 25 ++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Program.cs b/EventsHandler/Api/EventsHandler/Program.cs index 0ec42939..9f6ca50d 100644 --- a/EventsHandler/Api/EventsHandler/Program.cs +++ b/EventsHandler/Api/EventsHandler/Program.cs @@ -166,11 +166,18 @@ private static WebApplicationBuilder AddNetServices(this WebApplicationBuilder b // Swagger UI: Examples (showing custom values of API parameters instead of the default ones) builder.Services.AddSwaggerExamplesFromAssemblyOf(); - - // Logging (using "Sentry.io") - SentrySdk.Init(options => + + // Add logging using Sentry + builder.WebHost.UseSentry(options => { - options.ConfigureSentryOptions(SentryLevel.Info, isDebugEnabled: false); + if (builder.Environment.IsDevelopment()) + { + options.ConfigureSentryOptions(SentryLevel.Debug, isDebugEnabled: true); + } + else + { + options.ConfigureSentryOptions(SentryLevel.Info, isDebugEnabled: false); + } }); return builder; @@ -274,20 +281,14 @@ private static void RegisterResponders(this IServiceCollection services) private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder builder) { WebApplication app = builder.Build(); - + // Development settings if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); - - SentrySdk.Init(options => - { - options.ConfigureSentryOptions(SentryLevel.Debug, isDebugEnabled: true); - }); } - // Production settings app.UseHttpsRedirection(); // Try to redirect from HTTP to HTTPS (after first HTTP call) app.UseAuthentication(); @@ -295,6 +296,8 @@ private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder b app.MapControllers(); // Mapping actions from API controllers + app.UseSentryTracing(); + return app; } From 30af8fc6004d4f51d62e8fa035281afbd0c1c9e8 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Fri, 26 Apr 2024 15:47:02 +0200 Subject: [PATCH 13/22] Update Sentry DSN --- EventsHandler/Api/EventsHandler/Program.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Program.cs b/EventsHandler/Api/EventsHandler/Program.cs index 9f6ca50d..d2b74035 100644 --- a/EventsHandler/Api/EventsHandler/Program.cs +++ b/EventsHandler/Api/EventsHandler/Program.cs @@ -180,6 +180,8 @@ private static WebApplicationBuilder AddNetServices(this WebApplicationBuilder b } }); + builder.Services.AddSentryTunneling(); + return builder; } @@ -296,7 +298,8 @@ private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder b app.MapControllers(); // Mapping actions from API controllers - app.UseSentryTracing(); + app.UseSentryTunneling(); + app.UseSentryTracing(); // Enable Sentry to trace issues per requests return app; } @@ -311,7 +314,7 @@ private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder b private static void ConfigureSentryOptions(this SentryOptions options, SentryLevel diagnosticLevel, bool isDebugEnabled) { // Sentry Data Source Name (DSN) => where to log application events - options.Dsn = "https://4dfba3b56e7a177e0dead03ad82fa9c8@o4506671778168832.ingest.sentry.io/4506772979777536"; + options.Dsn = "https://1db70f552fb2bdcab8571661a3db6d70@o4507152178741248.ingest.de.sentry.io/4507152289431632"; // Informational messages are the most detailed to log options.DiagnosticLevel = diagnosticLevel; @@ -326,7 +329,7 @@ private static void ConfigureSentryOptions(this SentryOptions options, SentryLev options.IsGlobalModeEnabled = false; // The identifier indicating to which or on which platform / system the application is meant to run - options.Distribution = $"{Environment.OSVersion.Platform} | {Environment.OSVersion.VersionString}"; + options.Distribution = $"{Environment.OSVersion.Platform} ({Environment.OSVersion.VersionString})"; // Version of the application ("OMC Web API" in this case) options.Release = DefaultValues.ApiController.Version; From 77b8abd31f99ac5cabe70045aa15d9f42744cd6a Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Fri, 26 Apr 2024 15:53:10 +0200 Subject: [PATCH 14/22] TODO notes in models --- .../Behaviors/Mapping/Models/POCOs/OpenKlant/CitizenData.cs | 2 +- .../Behaviors/Mapping/Models/POCOs/OpenZaak/Case.cs | 2 ++ .../Behaviors/Mapping/Models/POCOs/OpenZaak/CaseStatusType.cs | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenKlant/CitizenData.cs b/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenKlant/CitizenData.cs index 2f72bb34..4fe650d6 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenKlant/CitizenData.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenKlant/CitizenData.cs @@ -52,7 +52,7 @@ public struct CitizenData : IJsonSerializable [JsonInclude] [JsonPropertyName("geslachtsaanduiding")] [JsonPropertyOrder(3)] - public string GenderCode { get; internal set; } = string.Empty; + public string GenderCode { get; internal set; } = string.Empty; // TODO: Remove Gender Code in the future /// [JsonInclude] diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/Case.cs b/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/Case.cs index 5d57c520..6494701e 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/Case.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/Case.cs @@ -27,6 +27,8 @@ public struct Case : IJsonSerializable [JsonPropertyOrder(2)] public string Identification { get; internal set; } = string.Empty; + // TODO: "zaaktype" might be used as well + /// /// Initializes a new instance of the struct. /// diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/CaseStatusType.cs b/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/CaseStatusType.cs index 3926ca05..ab658bad 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/CaseStatusType.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Mapping/Models/POCOs/OpenZaak/CaseStatusType.cs @@ -27,6 +27,8 @@ public struct CaseStatusType : IJsonSerializable [JsonPropertyOrder(1)] public bool IsFinalStatus { get; internal set; } + // TODO: "informeren" JSON property might be used in the future + /// /// Initializes a new instance of the struct. /// From 28fd645cd982047ef05d698b03587ee9286d13cc Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 09:57:26 +0200 Subject: [PATCH 15/22] Add word to discionary of exceptions --- NotifyNL.sln.DotSettings | 1 + 1 file changed, 1 insertion(+) diff --git a/NotifyNL.sln.DotSettings b/NotifyNL.sln.DotSettings index a9f5cf26..2121d4e3 100644 --- a/NotifyNL.sln.DotSettings +++ b/NotifyNL.sln.DotSettings @@ -41,6 +41,7 @@ True True True + True True True True From 0efd270186110b5cbbdfc76f5a229f25ef8a7e6b Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 10:01:41 +0200 Subject: [PATCH 16/22] Rearrange methods --- .../Controllers/Base/OmcController.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs index aa50dba3..16c8efb7 100644 --- a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs +++ b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs @@ -30,6 +30,14 @@ protected OmcController(ILogger logger) this._logger = logger; } + /// + /// Logs the API response. + /// + protected void LogApiResponse(LogLevel logLevel, ObjectResult objectResult) + { + _ = LogAndReturnApiResponse(logLevel, objectResult); + } + /// /// Logs and returns the API response. /// @@ -62,13 +70,5 @@ protected void LogApiResponse(LogLevel logLevel, string logMessage) { this._logger.Log(logLevel, $"OMC: {logMessage} | {DateTime.Now}"); } - - /// - /// Logs the API response. - /// - protected void LogApiResponse(LogLevel logLevel, ObjectResult objectResult) - { - _ = LogAndReturnApiResponse(logLevel, objectResult); - } } } \ No newline at end of file From 3363a7775d5f3b44e07e2dbc425342f34d285b85 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 10:02:00 +0200 Subject: [PATCH 17/22] Not used import --- .../Controllers/EventsControllerTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs b/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs index 0aaa435a..ac469316 100644 --- a/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs +++ b/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs @@ -5,7 +5,6 @@ using EventsHandler.Behaviors.Responding.Messages.Models.Base; using EventsHandler.Behaviors.Responding.Messages.Models.Details; using EventsHandler.Behaviors.Responding.Messages.Models.Errors; -using EventsHandler.Behaviors.Responding.Messages.Models.Information; using EventsHandler.Behaviors.Responding.Messages.Models.Successes; using EventsHandler.Behaviors.Responding.Results.Builder; using EventsHandler.Controllers; From 64d812cc5e66f7e421a78712ce12327c518a1f6f Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 10:08:28 +0200 Subject: [PATCH 18/22] Remove usage of obsolete parameter --- .../DataReceiving/Factories/NotificationClientFactory.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Services/DataReceiving/Factories/NotificationClientFactory.cs b/EventsHandler/Api/EventsHandler/Services/DataReceiving/Factories/NotificationClientFactory.cs index cfd93b1d..79123035 100644 --- a/EventsHandler/Api/EventsHandler/Services/DataReceiving/Factories/NotificationClientFactory.cs +++ b/EventsHandler/Api/EventsHandler/Services/DataReceiving/Factories/NotificationClientFactory.cs @@ -1,7 +1,6 @@ // © 2023, Worth Systems. using EventsHandler.Configuration; -using EventsHandler.Properties; using EventsHandler.Services.DataReceiving.Factories.Interfaces; using EventsHandler.Services.DataSending.Clients.Decorator; using EventsHandler.Services.DataSending.Clients.Interfaces; @@ -13,22 +12,18 @@ namespace EventsHandler.Services.DataReceiving.Factories internal sealed class NotificationClientFactory : IHttpClientFactory { private readonly WebApiConfiguration _configuration; - private readonly ILogger _logger; /// /// Initializes a new instance of the class. /// - public NotificationClientFactory(WebApiConfiguration configuration, ILogger logger) + public NotificationClientFactory(WebApiConfiguration configuration) { this._configuration = configuration; - this._logger = logger; } /// - INotifyClient IHttpClientFactory.GetHttpClient(string organizationId) + INotifyClient IHttpClientFactory.GetHttpClient(string _) { - this._logger.LogInformation($"{Resources.Logging_Client_Initialized} {organizationId}"); - return new NotifyClientDecorator( new NotificationClient( baseUrl: this._configuration.OMC.API.BaseUrl.NotifyNL(), // The base URL to "Notify NL" API Service From af4b4e39f22a1aa37cf4ab93b5abd3a2f4b7778a Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 12:52:14 +0200 Subject: [PATCH 19/22] Overloads of ToString() method to standardize closer to the source on how the details will be displayed --- .../Messages/Models/Base/BaseApiStandardResponseBody.cs | 6 ++++++ .../Models/Base/BaseEnhancedStandardResponseBody.cs | 6 ++++++ .../Messages/Models/Base/BaseSimpleStandardResponseBody.cs | 6 ++++++ .../Api/EventsHandler/Controllers/Base/OmcController.cs | 7 +++---- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs index eaf8c3f7..09c6935b 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs @@ -26,5 +26,11 @@ protected BaseApiStandardResponseBody(HttpStatusCode statusCode, string statusDe this.StatusCode = statusCode; this.StatusDescription = statusDescription; } + + /// + public override string ToString() + { + return $"Description: {StatusDescription}"; + } } } \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs index 3875c28f..7c718ca4 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs @@ -24,5 +24,11 @@ protected BaseEnhancedStandardResponseBody(HttpStatusCode statusCode, string sta { this.Details = details; } + + /// + public sealed override string ToString() + { + return $"Description: {StatusDescription} | Details: {Details.Message}"; + } } } \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs index 57d94f6f..57a53cb4 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs @@ -24,5 +24,11 @@ protected BaseSimpleStandardResponseBody(HttpStatusCode statusCode, string statu { this.Details = details; } + + /// + public sealed override string ToString() + { + return $"Description: {StatusDescription} | Details: {Details.Message}"; + } } } \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs index 16c8efb7..708c16dc 100644 --- a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs +++ b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs @@ -47,12 +47,11 @@ protected ObjectResult LogAndReturnApiResponse(LogLevel logLevel, ObjectResult o string logMessage = objectResult.Value switch { // Description with message - BaseEnhancedStandardResponseBody detailedResponseBody - => $"{detailedResponseBody.StatusDescription} | {detailedResponseBody.Details.Message}", + BaseEnhancedStandardResponseBody enhancedResponse => enhancedResponse.ToString(), + BaseSimpleStandardResponseBody simpleResponse => simpleResponse.ToString(), // Only description - BaseApiStandardResponseBody shortResponseBody - => shortResponseBody.StatusDescription, + BaseApiStandardResponseBody baseResponse => baseResponse.ToString(), // Unknown object result _ => $"Not standardized API response | {objectResult.StatusCode} | {nameof(objectResult.Value)}" From aac01ade493eaf65c8dd1f1498cd573aeb68a312 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 12:52:49 +0200 Subject: [PATCH 20/22] Missing documenation --- .../Controllers/Base/OmcController.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs index 708c16dc..ccb0ef31 100644 --- a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs +++ b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs @@ -21,23 +21,6 @@ public abstract class OmcController : Controller { private readonly ILogger _logger; - /// - /// Initializes a new instance of the class. - /// - /// The generic logger to be used. - protected OmcController(ILogger logger) - { - this._logger = logger; - } - - /// - /// Logs the API response. - /// - protected void LogApiResponse(LogLevel logLevel, ObjectResult objectResult) - { - _ = LogAndReturnApiResponse(logLevel, objectResult); - } - /// /// Logs and returns the API response. /// @@ -65,6 +48,8 @@ protected ObjectResult LogAndReturnApiResponse(LogLevel logLevel, ObjectResult o /// /// Logs the API response. /// + /// The severity of the log. + /// The message to be logged. protected void LogApiResponse(LogLevel logLevel, string logMessage) { this._logger.Log(logLevel, $"OMC: {logMessage} | {DateTime.Now}"); From cbbe078586f0bc91ed1fba1fad1ceb088b03bddf Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 13:46:24 +0200 Subject: [PATCH 21/22] First version of logging to Sentry --- .../Base/BaseApiStandardResponseBody.cs | 2 +- .../Base/BaseEnhancedStandardResponseBody.cs | 2 +- .../Base/BaseSimpleStandardResponseBody.cs | 2 +- .../Controllers/Base/OmcController.cs | 87 ++++++++++++++----- .../Controllers/EventsController.cs | 14 +-- .../Controllers/NotifyController.cs | 40 ++++----- .../Controllers/TestController.cs | 24 +++-- EventsHandler/Api/EventsHandler/Program.cs | 11 ++- .../Properties/Resources.Designer.cs | 18 ++-- .../EventsHandler/Properties/Resources.resx | 11 +-- .../Controllers/EventsControllerTests.cs | 8 +- 11 files changed, 128 insertions(+), 91 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs index 09c6935b..aa54cc03 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseApiStandardResponseBody.cs @@ -30,7 +30,7 @@ protected BaseApiStandardResponseBody(HttpStatusCode statusCode, string statusDe /// public override string ToString() { - return $"Description: {StatusDescription}"; + return StatusDescription; } } } \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs index 7c718ca4..a839933b 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseEnhancedStandardResponseBody.cs @@ -28,7 +28,7 @@ protected BaseEnhancedStandardResponseBody(HttpStatusCode statusCode, string sta /// public sealed override string ToString() { - return $"Description: {StatusDescription} | Details: {Details.Message}"; + return $"{StatusDescription} | {Details.Message}"; } } } \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs index 57a53cb4..970864df 100644 --- a/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs +++ b/EventsHandler/Api/EventsHandler/Behaviors/Responding/Messages/Models/Base/BaseSimpleStandardResponseBody.cs @@ -28,7 +28,7 @@ protected BaseSimpleStandardResponseBody(HttpStatusCode statusCode, string statu /// public sealed override string ToString() { - return $"Description: {StatusDescription} | Details: {Details.Message}"; + return $"{StatusDescription} | {Details.Message}"; } } } \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs index ccb0ef31..84be3d03 100644 --- a/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs +++ b/EventsHandler/Api/EventsHandler/Controllers/Base/OmcController.cs @@ -19,40 +19,87 @@ namespace EventsHandler.Controllers.Base [ProducesResponseType(StatusCodes.Status401Unauthorized, Type = typeof(string))] // REASON: JWT Token is invalid or expired public abstract class OmcController : Controller { - private readonly ILogger _logger; + // ReSharper disable MemberCanBeMadeStatic.Global /// - /// Logs and returns the API response. + /// Logs the message and returns the API response. /// - protected ObjectResult LogAndReturnApiResponse(LogLevel logLevel, ObjectResult objectResult) + /// The severity of the log. + /// The result to be analyzed before logging it. + protected ObjectResult LogApiResponse(LogLevel logLevel, ObjectResult objectResult) { - // Determine log message based on the received ObjectResult - string logMessage = objectResult.Value switch - { - // Description with message - BaseEnhancedStandardResponseBody enhancedResponse => enhancedResponse.ToString(), - BaseSimpleStandardResponseBody simpleResponse => simpleResponse.ToString(), - - // Only description - BaseApiStandardResponseBody baseResponse => baseResponse.ToString(), - - // Unknown object result - _ => $"Not standardized API response | {objectResult.StatusCode} | {nameof(objectResult.Value)}" - }; - - LogApiResponse(logLevel, logMessage); + LogMessage(logLevel, DetermineResultMessage(objectResult)); return objectResult; } /// - /// Logs the API response. + /// Logs the message. /// /// The severity of the log. /// The message to be logged. protected void LogApiResponse(LogLevel logLevel, string logMessage) { - this._logger.Log(logLevel, $"OMC: {logMessage} | {DateTime.Now}"); + LogMessage(logLevel, logMessage); + } + + /// + /// Logs the exception and returns the API response. + /// + /// The exception to be passed. + /// The result to be analyzed before logging it. + protected ObjectResult LogApiResponse(Exception exception, ObjectResult objectResult) + { + LogException(exception); + + return objectResult; + } + + // ReSharper enable MemberCanBeMadeStatic.Global + + #region Sentry logging + private static readonly Dictionary s_logMapping = new() + { + { LogLevel.Trace, SentryLevel.Debug }, + { LogLevel.Debug, SentryLevel.Debug }, + { LogLevel.Information, SentryLevel.Info }, + { LogLevel.Warning, SentryLevel.Warning }, + { LogLevel.Error, SentryLevel.Error }, + { LogLevel.Critical, SentryLevel.Fatal } + }; + + /// + private static void LogMessage(LogLevel logLevel, string logMessage) + { + _ = SentrySdk.CaptureMessage($"OMC | {logMessage}", s_logMapping[logLevel]); + } + + /// + private static void LogException(Exception exception) + { + _ = SentrySdk.CaptureException(exception); + } + #endregion + + #region Helper methods + /// + /// Determines the log message based on the received . + /// + private static string DetermineResultMessage(ObjectResult objectResult) + { + return objectResult.Value switch + { + // Description with message + BaseEnhancedStandardResponseBody enhancedResponse => enhancedResponse.ToString(), + BaseSimpleStandardResponseBody simpleResponse => simpleResponse.ToString(), + + // Only description + BaseApiStandardResponseBody baseResponse => baseResponse.ToString(), + + // Unknown object result + _ => $"Not standardized API response | {objectResult.StatusCode} | {nameof(objectResult.Value)}" + }; } + #endregion } } \ No newline at end of file diff --git a/EventsHandler/Api/EventsHandler/Controllers/EventsController.cs b/EventsHandler/Api/EventsHandler/Controllers/EventsController.cs index 0bc529e7..2d9c89bc 100644 --- a/EventsHandler/Api/EventsHandler/Controllers/EventsController.cs +++ b/EventsHandler/Api/EventsHandler/Controllers/EventsController.cs @@ -41,14 +41,11 @@ private static readonly (ProcessingResult, string) s_failedResult = /// The input validating service. /// The input processing service (business logic). /// The output standardization service (UX/UI). - /// The logging service registering API events. public EventsController( ISerializationService serializer, IValidationService validator, IProcessingService processor, - IRespondingService responder, - ILogger logger) - : base(logger) + IRespondingService responder) { this._serializer = serializer; this._validator = validator; @@ -89,15 +86,16 @@ public async Task ListenAsync([Required, FromBody] object json) return this._validator.Validate(ref notification) is HealthCheck.OK_Valid or HealthCheck.OK_Inconsistent // Try to process received notification - ? LogAndReturnApiResponse(LogLevel.Information, + ? LogApiResponse(LogLevel.Information, this._responder.Get_Processing_Status_ActionResult(await this._processor.ProcessAsync(notification), notification.Details)) + // Notification cannot be processed - : LogAndReturnApiResponse(LogLevel.Error, + : LogApiResponse(LogLevel.Error, this._responder.Get_Processing_Status_ActionResult(s_failedResult, notification.Details)); } catch (Exception exception) { - return LogAndReturnApiResponse(LogLevel.Critical, + return LogApiResponse(exception, this._responder.Get_Exception_ActionResult(exception)); } } @@ -115,6 +113,8 @@ or HealthCheck.OK_Inconsistent [ProducesResponseType(StatusCodes.Status200OK)] public IActionResult Version() { + LogApiResponse(LogLevel.Trace, Resources.Events_ApiVersionRequested); + return Ok(DefaultValues.ApiController.Version); } } diff --git a/EventsHandler/Api/EventsHandler/Controllers/NotifyController.cs b/EventsHandler/Api/EventsHandler/Controllers/NotifyController.cs index 17096c72..e7aa7d3a 100644 --- a/EventsHandler/Api/EventsHandler/Controllers/NotifyController.cs +++ b/EventsHandler/Api/EventsHandler/Controllers/NotifyController.cs @@ -37,13 +37,10 @@ public sealed class NotifyController : OmcController /// The input de(serializing) service. /// The output standardization service (UX/UI). /// The telemetry service registering API events. - /// The logging service registering API events. public NotifyController( ISerializationService serializer, IRespondingService responder, - ITelemetryService telemetry, - ILogger logger) - : base(logger) + ITelemetryService telemetry) { this._serializer = serializer; this._responder = responder; @@ -76,28 +73,28 @@ public async Task ConfirmAsync([Required, FromBody] object json) // Deserialize received JSON payload callback = this._serializer.Deserialize(json); - if (callback.Status is not (DeliveryStatus.PermanentFailure or - DeliveryStatus.TemporaryFailure or - DeliveryStatus.TechnicalFailure)) - { - return LogAndReturnApiResponse(LogLevel.Information, - this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Success, callbackDetails = GetCallbackDetails(callback))); - } + return callback.Status is not (DeliveryStatus.PermanentFailure or + DeliveryStatus.TemporaryFailure or + DeliveryStatus.TechnicalFailure) + // Positive status was returned by Notify NL + ? LogApiResponse(LogLevel.Information, + this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Success, callbackDetails = GetCallbackDetails(callback))) - return LogAndReturnApiResponse(LogLevel.Error, - this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Failure, callbackDetails = GetCallbackDetails(callback))); + // Failure status was returned by Notify NL + : LogApiResponse(LogLevel.Error, + this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Failure, callbackDetails = GetCallbackDetails(callback))); } catch (Exception exception) { - // NOTE: If callback.Id == Guid.Empty then to be suspected is exception during DeliveryReceipt deserialization + // NOTE: If callback.Id == Guid.Empty then it might be suspected that exception occurred during DeliveryReceipt deserialization callbackDetails = GetErrorDetails(callback, exception); - return LogAndReturnApiResponse(LogLevel.Critical, + return LogApiResponse(exception, this._responder.Get_Exception_ActionResult(exception)); } finally { - await ReportAndLogStatusAsync(callback, callbackDetails); + await LogContactRegistrationAsync(callback, callbackDetails); } } @@ -112,7 +109,7 @@ private static string GetErrorDetails(DeliveryReceipt callback, Exception except return $"{Resources.Feedback_NotifyNL_ERROR_UnexpectedFailure} {callback.Id}: {exception.Message}."; } - private async Task ReportAndLogStatusAsync(DeliveryReceipt callback, string callbackDetails) + private async Task LogContactRegistrationAsync(DeliveryReceipt callback, string callbackDetails) { if (callback.Reference != null) { @@ -122,13 +119,14 @@ private async Task ReportAndLogStatusAsync(DeliveryReceipt callback, string call try { - string result = await this._telemetry.ReportCompletionAsync(notification, notificationMethod, callbackDetails); - - LogApiResponse(LogLevel.Information, result); + LogApiResponse(LogLevel.Information, + await this._telemetry.ReportCompletionAsync(notification, notificationMethod, callbackDetails)); } catch (Exception exception) { - LogApiResponse(LogLevel.Critical, this._responder.Get_Exception_ActionResult(exception)); + // It wasn't possible to report completion because of issue with Telemetry Service + LogApiResponse(exception, + this._responder.Get_Exception_ActionResult(exception)); } } } diff --git a/EventsHandler/Api/EventsHandler/Controllers/TestController.cs b/EventsHandler/Api/EventsHandler/Controllers/TestController.cs index 1e9d03a5..9dd18b06 100644 --- a/EventsHandler/Api/EventsHandler/Controllers/TestController.cs +++ b/EventsHandler/Api/EventsHandler/Controllers/TestController.cs @@ -40,14 +40,11 @@ public sealed class TestController : OmcController /// The input de(serializing) service. /// The telemetry service registering API events. /// The output standardization service (UX/UI). - /// The logging service registering API events. public TestController( WebApiConfiguration configuration, ISerializationService serializer, ITelemetryService telemetry, - IRespondingService responder, - ILogger logger) - : base(logger) + IRespondingService responder) { this._configuration = configuration; this._serializer = serializer; @@ -82,16 +79,17 @@ public async Task HealthCheckAsync() // Response return result.IsSuccessStatusCode // HttpStatus Code: 202 Accepted - ? LogAndReturnApiResponse(LogLevel.Information, + ? LogApiResponse(LogLevel.Information, this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Success, result.ToString())) + // HttpStatus Code: 400 Bad Request - : LogAndReturnApiResponse(LogLevel.Error, + : LogApiResponse(LogLevel.Error, this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Failure, result.ToString())); } catch (Exception exception) { // HttpStatus Code: 500 Internal Server Error - return LogAndReturnApiResponse(LogLevel.Critical, + return LogApiResponse(exception, this._responder.Get_Exception_ActionResult(exception)); } } @@ -204,13 +202,13 @@ public async Task RegisterAsync( string result = await this._telemetry.ReportCompletionAsync(notification, NotifyMethods.Email, "test"); // TODO: Use notification method and message as parameters // HttpStatus Code: 202 Accepted - return LogAndReturnApiResponse(LogLevel.Information, + return LogApiResponse(LogLevel.Information, this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Success, result)); } catch (Exception exception) { // HttpStatus Code: 500 Internal Server Error - return LogAndReturnApiResponse(LogLevel.Critical, + return LogApiResponse(exception, this._responder.Get_Exception_ActionResult(exception)); } } @@ -265,7 +263,7 @@ private async Task SendAsync( break; default: - return LogAndReturnApiResponse(LogLevel.Error, + return LogApiResponse(LogLevel.Error, this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Failure, GetFailureMessage())); } } @@ -283,19 +281,19 @@ private async Task SendAsync( break; default: - return LogAndReturnApiResponse(LogLevel.Error, + return LogApiResponse(LogLevel.Error, this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Failure, GetFailureMessage())); } } // HttpStatus Code: 202 Accepted - return LogAndReturnApiResponse(LogLevel.Information, + return LogApiResponse(LogLevel.Information, this._responder.Get_Processing_Status_ActionResult(ProcessingResult.Success, GetSuccessMessage(templateType))); } catch (Exception exception) { // HttpStatus Code: 500 Internal Server Error - return LogAndReturnApiResponse(LogLevel.Critical, + return LogApiResponse(exception, this._responder.Get_Exception_ActionResult(exception)); } } diff --git a/EventsHandler/Api/EventsHandler/Program.cs b/EventsHandler/Api/EventsHandler/Program.cs index d2b74035..8d9cc99f 100644 --- a/EventsHandler/Api/EventsHandler/Program.cs +++ b/EventsHandler/Api/EventsHandler/Program.cs @@ -166,22 +166,22 @@ private static WebApplicationBuilder AddNetServices(this WebApplicationBuilder b // Swagger UI: Examples (showing custom values of API parameters instead of the default ones) builder.Services.AddSwaggerExamplesFromAssemblyOf(); - - // Add logging using Sentry + + // Add logging using Sentry SDK and external monitoring service builder.WebHost.UseSentry(options => { if (builder.Environment.IsDevelopment()) { + // More detailed (but spamming) settings for logs options.ConfigureSentryOptions(SentryLevel.Debug, isDebugEnabled: true); } else { + // Less detailed but more meaningful and noisy settings for logs options.ConfigureSentryOptions(SentryLevel.Info, isDebugEnabled: false); } }); - builder.Services.AddSentryTunneling(); - return builder; } @@ -298,8 +298,7 @@ private static WebApplication ConfigureHttpPipeline(this WebApplicationBuilder b app.MapControllers(); // Mapping actions from API controllers - app.UseSentryTunneling(); - app.UseSentryTracing(); // Enable Sentry to trace issues per requests + app.UseSentryTracing(); // Enable Sentry to capture transactions return app; } diff --git a/EventsHandler/Api/EventsHandler/Properties/Resources.Designer.cs b/EventsHandler/Api/EventsHandler/Properties/Resources.Designer.cs index a6efca6f..0308830f 100644 --- a/EventsHandler/Api/EventsHandler/Properties/Resources.Designer.cs +++ b/EventsHandler/Api/EventsHandler/Properties/Resources.Designer.cs @@ -276,6 +276,15 @@ internal static string Deserialization_INFO_UnexpectedData_Notification_Reason2 } } + /// + /// Looks up a localized string similar to Version of the API was requested. + /// + internal static string Events_ApiVersionRequested { + get { + return ResourceManager.GetString("Events_ApiVersionRequested", resourceCulture); + } + } + /// /// Looks up a localized string similar to An unexpected error occurred during processing the notification with ID. /// @@ -411,15 +420,6 @@ internal static string HttpRequest_ERROR_Reason2 { } } - /// - /// Looks up a localized string similar to The Http Client was initialized for organization:. - /// - internal static string Logging_Client_Initialized { - get { - return ResourceManager.GetString("Logging_Client_Initialized", resourceCulture); - } - } - /// /// Looks up a localized string similar to An unknown validation issue occurred.. /// diff --git a/EventsHandler/Api/EventsHandler/Properties/Resources.resx b/EventsHandler/Api/EventsHandler/Properties/Resources.resx index 545f338d..f983fccc 100644 --- a/EventsHandler/Api/EventsHandler/Properties/Resources.resx +++ b/EventsHandler/Api/EventsHandler/Properties/Resources.resx @@ -288,9 +288,6 @@ The configuration does not contain a given value, or it is empty: - - The Http Client was initialized for organization: - The looked up Environment Variable could not be found or the key is missing / not existing. @@ -308,11 +305,11 @@ This notification method is not supported. - API Endpoint: TestController/Notify/ + API Endpoint: Test/Notify/SendEmail or SendSms was successfully send to NotifyNL. - API Endpoint: TestController/Notify/ + API Endpoint: Test/Notify/SendEmail or SendSms The notification was passed to NotifyNL API. @@ -325,4 +322,8 @@ The status of notification with ID API Endpoint: Notify/Confirm + + Version of the API was requested + API Endpoint: Events/Version + \ No newline at end of file diff --git a/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs b/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs index ac469316..7f9fbc39 100644 --- a/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs +++ b/EventsHandler/Tests/IntegrationTests/EventsHandler.IntegrationTests/Controllers/EventsControllerTests.cs @@ -16,7 +16,6 @@ using EventsHandler.Services.Validation.Interfaces; using EventsHandler.Utilities._TestHelpers; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; using System.Net; using System.Text.Json; @@ -31,7 +30,6 @@ public sealed class EventsControllerTests private Mock> _validatorMock = new(); private Mock> _processorMock = new(); private Mock> _responderMock = new(); - private Mock> _loggerMock = new(); [OneTimeSetUp] public void InitializeMocks() @@ -40,7 +38,6 @@ public void InitializeMocks() this._validatorMock = new Mock>(MockBehavior.Strict); this._processorMock = new Mock>(MockBehavior.Strict); this._responderMock = new Mock>(MockBehavior.Strict); - this._loggerMock = new Mock>(MockBehavior.Loose); } [SetUp] @@ -58,8 +55,6 @@ public void InitializeTests() this._processorMock.Reset(); this._responderMock.Reset(); - - this._loggerMock.Reset(); } #region Testing IActionResult API responses @@ -204,8 +199,7 @@ private static InfoDetails GetTestInfoDetails_Success() private EventsController GetTestEventsController_WithRealResponder() { return new EventsController(this._serializerMock.Object, this._validatorMock.Object, - this._processorMock.Object, GetRealResponderService(), - this._loggerMock.Object); + this._processorMock.Object, GetRealResponderService()); } private static IRespondingService GetRealResponderService() From 6e014f9c23b246cfcef300ac2aba03656c317750 Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Mon, 6 May 2024 13:46:38 +0200 Subject: [PATCH 22/22] Update API version --- Documentation/OMC - Documentation.md | 2 +- EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/OMC - Documentation.md b/Documentation/OMC - Documentation.md index 9cc84f79..0078e6b1 100644 --- a/Documentation/OMC - Documentation.md +++ b/Documentation/OMC - Documentation.md @@ -1,6 +1,6 @@ # OMC Documentation -v.1.6.9 +v.1.7.0 © 2024, Worth Systems. diff --git a/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs b/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs index 4660de95..85854e80 100644 --- a/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs +++ b/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs @@ -12,7 +12,7 @@ internal static class ApiController { internal const string Route = "[controller]"; - internal const string Version = "1.69"; + internal const string Version = "1.70"; } #endregion