synergy moats product advisory implementations

This commit is contained in:
master
2026-01-17 01:30:03 +02:00
parent 77ff029205
commit 702a27ac83
112 changed files with 21356 additions and 127 deletions

View File

@@ -0,0 +1,67 @@
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Http;
namespace StellaOps.Scheduler.WebService.Observability;
internal sealed class SchedulerTelemetryMiddleware
{
private static readonly ActivitySource ActivitySource = new("StellaOps.Scheduler.WebService");
private readonly RequestDelegate _next;
public SchedulerTelemetryMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
var operationName = $"{context.Request.Method} {context.Request.Path}";
using var activity = ActivitySource.StartActivity(operationName, ActivityKind.Server);
if (activity != null)
{
activity.SetTag("http.method", context.Request.Method);
activity.SetTag("http.route", context.GetEndpoint()?.DisplayName ?? context.Request.Path.ToString());
var tenantId = TryGetTenantId(context);
if (!string.IsNullOrWhiteSpace(tenantId))
{
activity.SetTag("tenant_id", tenantId);
}
if (context.Request.RouteValues.TryGetValue("scheduleId", out var scheduleId) && scheduleId is not null)
{
activity.SetTag("schedule_id", scheduleId.ToString());
}
if (context.Request.RouteValues.TryGetValue("runId", out var runId) && runId is not null)
{
activity.SetTag("run_id", runId.ToString());
activity.SetTag("job_id", runId.ToString());
}
}
try
{
await _next(context).ConfigureAwait(false);
}
finally
{
if (activity != null && context.Response.StatusCode >= 400)
{
activity.SetStatus(ActivityStatusCode.Error);
}
}
}
private static string? TryGetTenantId(HttpContext context)
{
if (context.Request.Headers.TryGetValue("X-Tenant-Id", out var header))
{
return header.ToString();
}
return context.User?.Claims?.FirstOrDefault(c => c.Type == "tenant_id")?.Value;
}
}

View File

@@ -20,6 +20,7 @@ using StellaOps.Scheduler.WebService.GraphJobs;
using StellaOps.Scheduler.WebService.GraphJobs.Events;
using StellaOps.Scheduler.WebService.Schedules;
using StellaOps.Scheduler.WebService.Options;
using StellaOps.Scheduler.WebService.Observability;
using StellaOps.Scheduler.WebService.PolicyRuns;
using StellaOps.Scheduler.WebService.PolicySimulations;
using StellaOps.Scheduler.WebService.VulnerabilityResolverJobs;
@@ -207,6 +208,7 @@ var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<SchedulerTelemetryMiddleware>();
app.TryUseStellaRouter(routerOptions);
if (!authorityOptions.Enabled)