Skip to content

Commit

Permalink
feat: or-2013 add initiator to otel tracing via middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
koenmetsu committed Dec 20, 2023
1 parent fb8cb97 commit 95a1dc1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions src/AssociationRegistry.Admin.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ private static void ConfigureMiddleware(IApplicationBuilder app)
})
.UseMiddleware<UnexpectedAggregateVersionMiddleware>()
.UseMiddleware<InitiatorHeaderMiddleware>()
.UseMiddleware<InitiatorActivityMiddleware>()
.UseResponseCompression();
}

Expand Down

0 comments on commit 95a1dc1

Please sign in to comment.