diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml index d2c2731..838710b 100644 --- a/.github/workflows/createrelease.yml +++ b/.github/workflows/createrelease.yml @@ -49,6 +49,10 @@ jobs: - name: Publish API if: ${{ github.event.release.prerelease == false }} run: dotnet publish "MessagingService\MessagingService.csproj" --configuration Release --output publishOutput -r win-x64 --self-contained false + -p:Version=${{ steps.get_version.outputs.VERSION }} + -p:AssemblyVersion=${{ steps.get_version.outputs.VERSION }} + -p:FileVersion=${{ steps.get_version.outputs.VERSION }} + -p:InformationalVersion=${{ steps.get_version.outputs.VERSION }} - name: Build Release Package run: | diff --git a/MessagingService/MessagingService.csproj b/MessagingService/MessagingService.csproj index d4fa809..4f3e52c 100644 --- a/MessagingService/MessagingService.csproj +++ b/MessagingService/MessagingService.csproj @@ -33,6 +33,7 @@ + diff --git a/MessagingService/Program.cs b/MessagingService/Program.cs index 2d89215..5db8d68 100644 --- a/MessagingService/Program.cs +++ b/MessagingService/Program.cs @@ -3,15 +3,18 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System; -using System.IO; using Shared.Logger; using Shared.Middleware; +using System; +using System.IO; +using System.Reflection; +using Sentry.Extensibility; namespace MessagingService { using Lamar.Microsoft.DependencyInjection; using NLog; + using Shared.General; using System.Diagnostics.CodeAnalysis; [ExcludeFromCodeCoverage] @@ -56,6 +59,45 @@ public static IHostBuilder CreateHostBuilder(string[] args) }).ConfigureWebHostDefaults(webBuilder => { + webBuilder.ConfigureAppConfiguration((context, configBuilder) => + { + var env = context.HostingEnvironment; + + configBuilder.SetBasePath(fi.Directory.FullName) + .AddJsonFile("hosting.json", optional: true) + .AddJsonFile($"hosting.{env.EnvironmentName}.json", optional: true) + .AddJsonFile("/home/txnproc/config/appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"/home/txnproc/config/appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) + .AddEnvironmentVariables(); + + // Build a snapshot of configuration so we can use it immediately (e.g. for Sentry) + var builtConfig = configBuilder.Build(); + + // Keep existing static usage (if you must), and initialise the ConfigurationReader now. + Startup.Configuration = builtConfig; + ConfigurationReader.Initialise(Startup.Configuration); + + // Configure Sentry on the webBuilder using the config snapshot. + var sentrySection = builtConfig.GetSection("SentryConfiguration"); + if (sentrySection.Exists()) + { + // Replace the condition below if you intended to only enable Sentry in certain environments. + if (env.IsDevelopment() == false) + { + webBuilder.UseSentry(o => + { + o.Dsn = builtConfig["SentryConfiguration:Dsn"]; + o.SendDefaultPii = true; + o.MaxRequestBodySize = RequestSize.Always; + o.CaptureBlockingCalls = true; + o.Release = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown"; + }); + } + } + }); + webBuilder.UseStartup(); webBuilder.UseConfiguration(config); webBuilder.UseKestrel(); diff --git a/MessagingService/Startup.cs b/MessagingService/Startup.cs index 86861ae..0a932c4 100644 --- a/MessagingService/Startup.cs +++ b/MessagingService/Startup.cs @@ -37,14 +37,6 @@ public class Startup { public Startup(IWebHostEnvironment webHostEnvironment) { - IConfigurationBuilder builder = new ConfigurationBuilder().SetBasePath(webHostEnvironment.ContentRootPath) - .AddJsonFile("/home/txnproc/config/appsettings.json", true, true) - .AddJsonFile($"/home/txnproc/config/appsettings.{webHostEnvironment.EnvironmentName}.json", optional: true) - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{webHostEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true) - .AddEnvironmentVariables(); - - Startup.Configuration = builder.Build(); Startup.WebHostEnvironment = webHostEnvironment; }