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
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.5.1" />
<PackageVersion Include="Azure.Identity" Version="1.21.0" />
<PackageVersion Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="1.5.0" />
<!-- TODO: update to stable release when Azure.Monitor.OpenTelemetry.Profiler reaches GA -->
<PackageVersion Include="Azure.Monitor.OpenTelemetry.Profiler" Version="1.0.0-beta9" />
<PackageVersion Include="TUnit" Version="1.40.5" />
<PackageVersion Include="EssentialCSharp.Shared.Models" Version="$(ToolingPackagesVersion)" />
<PackageVersion Include="HtmlAgilityPack" Version="1.12.4" />
Expand Down
1 change: 1 addition & 0 deletions EssentialCSharp.Web/EssentialCSharp.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<PackageReference Include="Azure.Extensions.AspNetCore.DataProtection.Keys" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Profiler" />
<PackageReference Include="EssentialCSharp.Shared.Models" />
<PackageReference Include="HtmlAgilityPack" />
<PackageReference Include="IntelliTect.Multitool" />
Expand Down
47 changes: 29 additions & 18 deletions EssentialCSharp.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.RateLimiting;
using Azure.Monitor.OpenTelemetry.AspNetCore;
using Azure.Monitor.OpenTelemetry.Profiler;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
Expand Down Expand Up @@ -90,7 +91,7 @@ private static void Main(string[] args)
});

if (useAzureMonitor)
otel.UseAzureMonitor();
otel.UseAzureMonitor().AddAzureMonitorProfiler();
else if (useOtlp)
otel.UseOtlpExporter();

Expand Down Expand Up @@ -511,7 +512,7 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
}
app.UseStaticFiles();

app.UseRouting();
app.UseRouting();

app.UseWhen(
context => context.Request.Path.StartsWithSegments("/mcp"),
Expand Down Expand Up @@ -542,10 +543,10 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
await next(context);
}));

app.UseRateLimiter();

app.UseAuthorization();
app.UseOutputCache();
app.UseRateLimiter();
app.UseAuthorization();
app.UseOutputCache();

app.UseMiddleware<ReferralMiddleware>();

Expand Down Expand Up @@ -584,13 +585,23 @@ await McpJsonRpcResponseWriter.WriteErrorAsync(
try
{
SitemapXmlHelpers.EnsureSitemapHealthy(siteMappingService.SiteMappings.ToList());
LogSitemapValidationSucceeded(logger);
}
catch (Exception ex)
{
LogSitemapValidationFailed(logger, ex);
// Continue startup even if sitemap validation fails
}
LogSitemapValidationSucceeded(logger);
}
catch (InvalidOperationException ex)
{
LogSitemapValidationFailed(logger, ex);
// Continue startup even if sitemap validation fails
}
catch (ArgumentException ex)
{
LogSitemapValidationFailed(logger, ex);
// Continue startup even if sitemap validation fails
}
catch (FormatException ex)
{
LogSitemapValidationFailed(logger, ex);
// Continue startup even if sitemap validation fails
}

app.Run();
}
Expand All @@ -604,11 +615,11 @@ private static bool IsMcpTransportRequest(HttpRequest request) =>
[LoggerMessage(Level = LogLevel.Error, Message = "Unhandled exception on {Path}")]
private static partial void LogUnhandledException(ILogger<Program> logger, Exception? exception, PathString path);

[LoggerMessage(Level = LogLevel.Information, Message = "Sitemap validation completed successfully during application startup")]
private static partial void LogSitemapValidationSucceeded(ILogger<Program> logger);

[LoggerMessage(Level = LogLevel.Error, Message = "Failed to validate sitemap during application startup")]
private static partial void LogSitemapValidationFailed(ILogger<Program> logger, Exception exception);
[LoggerMessage(Level = LogLevel.Information, Message = "Sitemap validation completed successfully during application startup")]
private static partial void LogSitemapValidationSucceeded(ILogger<Program> logger);
[LoggerMessage(Level = LogLevel.Error, Message = "Failed to validate sitemap during application startup")]
private static partial void LogSitemapValidationFailed(ILogger<Program> logger, Exception exception);

[LoggerMessage(Level = LogLevel.Warning, Message = "Ignoring invalid TryDotNet origin in CSP: {Origin}")]
private static partial void LogIgnoringInvalidTryDotNetOrigin(ILogger logger, string origin);
Expand Down
4 changes: 3 additions & 1 deletion EssentialCSharp.Web/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
"Microsoft.AspNetCore": "Warning",
"Microsoft.ServiceProfiler": "Debug",
"Azure.Monitor.OpenTelemetry.Profiler": "Debug"
}
},
"ConnectionStrings": {
Expand Down
Loading