feat(server): add observability and operator controls (#16)
quality-gate / quality (push) Failing after 1m1s
quality-gate / quality (push) Failing after 1m1s
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FinalFactory.Rendezvous.Server.Observability;
|
||||
|
||||
internal sealed class TelemetryMiddleware(
|
||||
RequestDelegate next,
|
||||
RendezvousTelemetry telemetry)
|
||||
{
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
string operation = context.GetEndpoint()?.Metadata.GetMetadata<IEndpointNameMetadata>()
|
||||
?.EndpointName ?? "Unmatched";
|
||||
long started = Stopwatch.GetTimestamp();
|
||||
using Activity? activity = telemetry.StartActivity(
|
||||
$"HTTP {operation}",
|
||||
ActivityKind.Server);
|
||||
string correlationId = activity?.TraceId.ToString() ?? Guid.NewGuid().ToString("N");
|
||||
context.Response.Headers["X-Rendezvous-Correlation-ID"] = correlationId;
|
||||
activity?.SetTag("rendezvous.operation", operation);
|
||||
try
|
||||
{
|
||||
await next(context).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
telemetry.RecordHttp(
|
||||
operation,
|
||||
context.Response.StatusCode,
|
||||
Stopwatch.GetElapsedTime(started).TotalMilliseconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user