Skip to content

Commit

Permalink
feat: Add more startup logging (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
killij authored Feb 29, 2024
1 parent 43df99f commit c7e3f09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
28 changes: 27 additions & 1 deletion Childrens-Social-Care-CPD/Program.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
using Childrens_Social_Care_CPD;
using Childrens_Social_Care_CPD.Configuration.Features;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

var builder = WebApplication.CreateBuilder(args);

var sw = new Stopwatch();
sw.Start();

builder.AddDependencies();
await builder.AddFeatures();
Console.WriteLine($"After AddDependencies {sw.ElapsedMilliseconds}ms");

await builder.AddFeatures(sw);
Console.WriteLine($"After AddFeatures {sw.ElapsedMilliseconds}ms");

var app = builder.Build();
Console.WriteLine($"After Application Build {sw.ElapsedMilliseconds}ms");

// Ensure the features are fetched before starting the app
var updater = app.Services.GetService<IFeaturesConfigUpdater>();
using (var cts = new CancellationTokenSource())
{
await updater.UpdateFeaturesAsync(cts.Token);
}
Console.WriteLine($"After UpdateFeaturesAsync {sw.ElapsedMilliseconds}ms");

app.UseResponseCompression();
Console.WriteLine($"After UseResponseCompression {sw.ElapsedMilliseconds}ms");

app.UseExceptionHandler("/error/error");
Console.WriteLine($"After UseExceptionHandler {sw.ElapsedMilliseconds}ms");

app.UseStatusCodePagesWithReExecute("/error/{0}");
Console.WriteLine($"After UseStatusCodePagesWithReExecute{sw.ElapsedMilliseconds}ms");

app.UseStaticFiles();
Console.WriteLine($"After UseStaticFiles {sw.ElapsedMilliseconds}ms");

app.UseRouting();
Console.WriteLine($"After UseRouting {sw.ElapsedMilliseconds}ms");

app.UseAuthorization();
Console.WriteLine($"After UseAuthorization {sw.ElapsedMilliseconds}ms");

app.MapControllerRoute(
name: "default",
pattern: "{controller=Content}/{action=Index}");
Console.WriteLine($"After MapControllerRoute {sw.ElapsedMilliseconds}ms");

app.MapHealthChecks("application/status");
Console.WriteLine($"After MapHealthChecks {sw.ElapsedMilliseconds}ms");

app.Run();
Console.WriteLine($"After Application Run {sw.ElapsedMilliseconds}ms");

[ExcludeFromCodeCoverage]
public partial class Program
Expand Down
10 changes: 5 additions & 5 deletions Childrens-Social-Care-CPD/WebApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ private static void AddSearch(IServiceCollection services)
services.AddScoped<ISearchService, SearchService>();
}

public static async Task AddFeatures(this WebApplicationBuilder builder)
public static async Task AddFeatures(this WebApplicationBuilder builder, Stopwatch sw)
{
ArgumentNullException.ThrowIfNull(builder);
var sw = new Stopwatch();
sw.Start();

builder.Configuration.AddUserSecrets<Program>();
Console.WriteLine($"After AddUserSecrets: {sw.ElapsedMilliseconds}ms");
Expand All @@ -125,7 +123,7 @@ public static async Task AddFeatures(this WebApplicationBuilder builder)
AddHealthChecks(builder.Services);
Console.WriteLine($"After AddHealthChecks: {sw.ElapsedMilliseconds}ms");

await AddDataProtection(builder.Services, applicationConfiguration);
await AddDataProtection(builder.Services, applicationConfiguration, sw);
Console.WriteLine($"After AddDataProtection: {sw.ElapsedMilliseconds}ms");
}

Expand Down Expand Up @@ -178,7 +176,7 @@ private static void AddHealthChecks(IServiceCollection services)
#pragma warning restore CA1861 // Avoid constant arrays as arguments
}

private static async Task AddDataProtection(IServiceCollection services, ApplicationConfiguration applicationConfiguration)
private static async Task AddDataProtection(IServiceCollection services, ApplicationConfiguration applicationConfiguration, Stopwatch sw)
{
if (!string.IsNullOrEmpty(applicationConfiguration.AzureDataProtectionContainerName))
{
Expand All @@ -187,10 +185,12 @@ private static async Task AddDataProtection(IServiceCollection services, Applica
applicationConfiguration.AzureDataProtectionContainerName);

var managedIdentityCredential = new ManagedIdentityCredential(clientId: applicationConfiguration.AzureManagedIdentityId);
Console.WriteLine($"After AddDataProtection:new ManagedIdentityCredential: {sw.ElapsedMilliseconds}ms");

var blobContainerUri = new Uri(url);
var blobContainerClient = new BlobContainerClient(blobContainerUri, managedIdentityCredential);
await blobContainerClient.CreateIfNotExistsAsync();
Console.WriteLine($"After AddDataProtection:blobContainerClient.CreateIfNotExistsAsync: {sw.ElapsedMilliseconds}ms");

var blobUri = new Uri($"{url}/data-protection");
services
Expand Down

0 comments on commit c7e3f09

Please sign in to comment.