-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consumer API: Correlation IDs are retained across domain event bounda…
…ries (#809) * fix: repair reference errors * feat: propagate correlation id across events via rabbitmq * feat: propagate correlation id across events via azure service bus * feat: propagate correlation id across events via pub sub * feat: add missing assembly reference * fix: update object instantiation * fix: repair failing tests * fix: repair failing tests * fix: repair failing licence tests * fix: missing correlation Ids for Azure EventBus * fix: EventHandlerService not postinng to seq * chore: fix formatting * fix: make CorrelationIds work without http context by introducing CustomLogContext * chore: remove unused classes * feat: don't use hyphens in generated correlation ids * chore: remove leftovers from former solution * chore: delete weird code from Messages.Infrastructure.csproj * chore: remove unused nuget package * feat: add RequestResponseTimeMiddleware, ResponseDurationMiddleware, TraceIdMiddleware and CorrelationIdMiddleware to Admin API --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Daniel Silva <[email protected]> Co-authored-by: Timo Notheisen <[email protected]>
- Loading branch information
1 parent
715afeb
commit 7b307dd
Showing
16 changed files
with
178 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
[ | ||
"Serilog.Enrichers.Demystifier", | ||
"SpecFlow.NUnit" | ||
] | ||
["Serilog.Enrichers.Demystifier", "SpecFlow.NUnit"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
BuildingBlocks/src/BuildingBlocks.API/Mvc/Middleware/CorrelationIdMiddleware.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Backbone.BuildingBlocks.Infrastructure.CorrelationIds; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Backbone.BuildingBlocks.API.Mvc.Middleware; | ||
|
||
public class CorrelationIdMiddleware | ||
{ | ||
private readonly RequestDelegate _next; | ||
|
||
public CorrelationIdMiddleware(RequestDelegate next) | ||
{ | ||
_next = next; | ||
} | ||
|
||
public async Task InvokeAsync(HttpContext context) | ||
{ | ||
var correlationId = context.Request.Headers["X-Correlation-ID"].FirstOrDefault(); | ||
|
||
if (string.IsNullOrEmpty(correlationId)) | ||
{ | ||
correlationId = CustomLogContext.GenerateCorrelationId(); | ||
} | ||
|
||
context.Response.Headers["X-Correlation-ID"] = correlationId; | ||
|
||
using (CustomLogContext.SetCorrelationId(correlationId)) | ||
{ | ||
await _next(context); | ||
} | ||
} | ||
} |
26 changes: 13 additions & 13 deletions
26
BuildingBlocks/src/BuildingBlocks.Infrastructure/BuildingBlocks.Infrastructure.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Autofac" Version="8.0.0" /> | ||
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.1" /> | ||
<PackageReference Include="Autofac" Version="8.0.0"/> | ||
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.1"/> | ||
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2"/> | ||
<PackageReference Include="Google.Cloud.PubSub.V1" Version="3.16.0"/> | ||
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.10.0"/> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8"/> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.8"/> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8"/> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8"/> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.8" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" /> | ||
<PackageReference Include="Polly" Version="8.4.1" /> | ||
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" /> | ||
<PackageReference Include="System.Interactive.Async" Version="6.0.1" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/> | ||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.8"/> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/> | ||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4"/> | ||
<PackageReference Include="Polly" Version="8.4.1"/> | ||
<PackageReference Include="RabbitMQ.Client" Version="6.8.1"/> | ||
<PackageReference Include="Serilog" Version="4.0.1"/> | ||
<PackageReference Include="System.Interactive.Async" Version="6.0.1"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\BuildingBlocks.Application.Abstractions\BuildingBlocks.Application.Abstractions.csproj" /> | ||
<ProjectReference Include="..\BuildingBlocks.Application.Abstractions\BuildingBlocks.Application.Abstractions.csproj"/> | ||
</ItemGroup> | ||
|
||
</Project> |
24 changes: 24 additions & 0 deletions
24
BuildingBlocks/src/BuildingBlocks.Infrastructure/CorrelationIds/CustomLogContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Serilog.Context; | ||
|
||
namespace Backbone.BuildingBlocks.Infrastructure.CorrelationIds; | ||
|
||
public static class CustomLogContext | ||
{ | ||
private static readonly AsyncLocal<string> CORRELATION_ID = new(); | ||
|
||
public static IDisposable SetCorrelationId(string correlationId) | ||
{ | ||
CORRELATION_ID.Value = correlationId; | ||
return LogContext.PushProperty("CorrelationId", correlationId); | ||
} | ||
|
||
public static string GetCorrelationId() | ||
{ | ||
return CORRELATION_ID.Value ?? ""; | ||
} | ||
|
||
public static string GenerateCorrelationId() | ||
{ | ||
return Guid.NewGuid().ToString("N"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.