diff --git a/src/AssociationRegistry.Admin.Api/Infrastructure/Middleware/InitiatorActivityMiddleware.cs b/src/AssociationRegistry.Admin.Api/Infrastructure/Middleware/InitiatorActivityMiddleware.cs new file mode 100644 index 000000000..5a7011ae4 --- /dev/null +++ b/src/AssociationRegistry.Admin.Api/Infrastructure/Middleware/InitiatorActivityMiddleware.cs @@ -0,0 +1,28 @@ +namespace AssociationRegistry.Admin.Api.Infrastructure.Middleware; + +using Microsoft.AspNetCore.Http; +using System.Diagnostics; +using System.Threading.Tasks; + +public class InitiatorActivityMiddleware +{ + private readonly RequestDelegate _next; + + public InitiatorActivityMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task InvokeAsync(HttpContext context) + { + if (context.Request.Headers.TryGetValue(WellknownHeaderNames.Initiator, out var headerValue)) + { + var currentActivity = Activity.Current; + if (currentActivity != null) + { + currentActivity.SetTag("vr.initiator", headerValue.ToString()); + } + } + await _next(context); + } +} diff --git a/src/AssociationRegistry.Admin.Api/Program.cs b/src/AssociationRegistry.Admin.Api/Program.cs index 24748aabd..3ab761836 100755 --- a/src/AssociationRegistry.Admin.Api/Program.cs +++ b/src/AssociationRegistry.Admin.Api/Program.cs @@ -278,6 +278,7 @@ private static void ConfigureMiddleware(IApplicationBuilder app) }) .UseMiddleware() .UseMiddleware() + .UseMiddleware() .UseResponseCompression(); }