Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 38 additions & 20 deletions CallbackHandler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,49 @@ public static IHostBuilder CreateHostBuilder(string[] args)
});
hostBuilder.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseConfiguration(config);
webBuilder.UseKestrel();

IConfigurationSection isSentryConfigured = config.GetSection("SentryConfiguration");
if (isSentryConfigured.Exists()) {
webBuilder.Configure((context,
app) => {
if (context.HostingEnvironment.IsDevelopment() == false) {
Version version = Assembly.GetExecutingAssembly().GetName().Version;

webBuilder.UseSentry(o => {

o.Dsn = ConfigurationReader.GetValueFromSection<String>("SentryConfiguration", "Dsn");
o.SendDefaultPii = true; // required for body + user data
// Configure per-environment configuration and build a snapshot so we can read settings here.
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.CaptureFailedRequests = true;
o.Release = version != null ? version.ToString() : "unknown";

o.Release = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown";
});
}
});
}
});

}
webBuilder.UseStartup<Startup>();
webBuilder.UseConfiguration(config);
webBuilder.UseKestrel();
});

return hostBuilder;
Expand Down
15 changes: 7 additions & 8 deletions CallbackHandler/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
{
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();
//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();

Check notice on line 33 in CallbackHandler/Startup.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

CallbackHandler/Startup.cs#L33

Remove this commented out code.

Startup.Configuration = builder.Build();
//Startup.Configuration = builder.Build();
Startup.WebHostEnvironment = webHostEnvironment;
}

Expand Down Expand Up @@ -109,7 +109,6 @@
app.UseSwagger();

app.UseSwaggerUI();

}
}
}
Loading