Skip to content

Commit 8772fca

Browse files
Merge pull request #618 from TransactionProcessing/task/#617_sentry_integration
Add Sentry integration and improve config handling
2 parents b1426c3 + b71fbf2 commit 8772fca

4 files changed

Lines changed: 49 additions & 10 deletions

File tree

.github/workflows/createrelease.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ jobs:
4848
- name: Publish API
4949
if: ${{ github.event.release.prerelease == false }}
5050
run: dotnet publish "TransactionProcessorACL\TransactionProcessorACL.csproj" --configuration Release --output publishOutput -r win-x64 --self-contained
51+
-p:Version=${{ steps.get_version.outputs.VERSION }}
52+
-p:AssemblyVersion=${{ steps.get_version.outputs.VERSION }}
53+
-p:FileVersion=${{ steps.get_version.outputs.VERSION }}
54+
-p:InformationalVersion=${{ steps.get_version.outputs.VERSION }}
5155

5256

5357
- name: Build Release Package

TransactionProcessorACL/Program.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.Hosting;
44
using Microsoft.Extensions.Logging;
5+
using Shared.Logger;
6+
using Shared.Middleware;
57
using System;
68
using System.Collections.Generic;
79
using System.Linq;
810
using System.Threading.Tasks;
9-
using Shared.Logger;
10-
using Shared.Middleware;
1111

1212
namespace TransactionProcessorACL
1313
{
1414
using Lamar.Microsoft.DependencyInjection;
1515
using NLog;
1616
using NLog.Extensions.Logging;
17+
using Sentry.Extensibility;
18+
using Shared.General;
1719
using System.Diagnostics.CodeAnalysis;
1820
using System.IO;
21+
using System.Reflection;
1922

2023
[ExcludeFromCodeCoverage]
2124
public class Program
@@ -60,6 +63,45 @@ public static IHostBuilder CreateHostBuilder(string[] args)
6063
});
6164
hostBuilder.ConfigureWebHostDefaults(webBuilder =>
6265
{
66+
webBuilder.ConfigureAppConfiguration((context, configBuilder) =>
67+
{
68+
var env = context.HostingEnvironment;
69+
70+
configBuilder.SetBasePath(fi.Directory.FullName)
71+
.AddJsonFile("hosting.json", optional: true)
72+
.AddJsonFile($"hosting.{env.EnvironmentName}.json", optional: true)
73+
.AddJsonFile("/home/txnproc/config/appsettings.json", optional: true, reloadOnChange: true)
74+
.AddJsonFile($"/home/txnproc/config/appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
75+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
76+
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
77+
.AddEnvironmentVariables();
78+
79+
// Build a snapshot of configuration so we can use it immediately (e.g. for Sentry)
80+
var builtConfig = configBuilder.Build();
81+
82+
// Keep existing static usage (if you must), and initialise the ConfigurationReader now.
83+
Startup.Configuration = builtConfig;
84+
ConfigurationReader.Initialise(Startup.Configuration);
85+
86+
// Configure Sentry on the webBuilder using the config snapshot.
87+
var sentrySection = builtConfig.GetSection("SentryConfiguration");
88+
if (sentrySection.Exists())
89+
{
90+
// Replace the condition below if you intended to only enable Sentry in certain environments.
91+
if (env.IsDevelopment() == false)
92+
{
93+
webBuilder.UseSentry(o =>
94+
{
95+
o.Dsn = builtConfig["SentryConfiguration:Dsn"];
96+
o.SendDefaultPii = true;
97+
o.MaxRequestBodySize = RequestSize.Always;
98+
o.CaptureBlockingCalls = true;
99+
o.Release = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
100+
});
101+
}
102+
}
103+
});
104+
63105
webBuilder.UseStartup<Startup>();
64106
webBuilder.UseConfiguration(config);
65107
webBuilder.UseKestrel();

TransactionProcessorACL/Startup.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ public class Startup
3636
{
3737
public Startup(IWebHostEnvironment webHostEnvironment)
3838
{
39-
IConfigurationBuilder builder = new ConfigurationBuilder().SetBasePath(webHostEnvironment.ContentRootPath)
40-
.AddJsonFile("/home/txnproc/config/appsettings.json", true, true)
41-
.AddJsonFile($"/home/txnproc/config/appsettings.{webHostEnvironment.EnvironmentName}.json", optional: true)
42-
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
43-
.AddJsonFile($"appsettings.{webHostEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
44-
.AddEnvironmentVariables();
45-
46-
Startup.Configuration = builder.Build();
4739
Startup.WebHostEnvironment = webHostEnvironment;
4840
}
4941

TransactionProcessorACL/TransactionProcessorACL.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.1.4" />
3737
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.4" />
3838
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="10.0.3" />
39+
<PackageReference Include="Sentry.AspNetCore" Version="6.2.0" />
3940
</ItemGroup>
4041

4142
<ItemGroup>

0 commit comments

Comments
 (0)