-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added missing logic in TracingMiddleware to actually get correlation …
…and causation ids from request headers
- Loading branch information
1 parent
9cef9cb
commit 2c07214
Showing
5 changed files
with
51 additions
and
16 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
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 Core.Tracing.Causation; | ||
using Core.Tracing.Correlation; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Core.WebApi.Tracing; | ||
|
||
public static class TracingHeadersExtensions | ||
{ | ||
private const string CorrelationIdHeaderName = "X-Correlation-ID"; | ||
private const string CausationIdHeaderName = "X-Causation-ID"; | ||
|
||
public static CorrelationId? GetCorrelationId(this HttpRequest request) => | ||
request.Headers.TryGetValue(CorrelationIdHeaderName, out var correlationId) | ||
? new CorrelationId(correlationId) | ||
: null; | ||
|
||
|
||
public static CausationId? GetCausationId(this HttpRequest request) => | ||
request.Headers.TryGetValue(CausationIdHeaderName, out var correlationId) | ||
? new CausationId(correlationId) | ||
: null; | ||
|
||
public static void SetCorrelationId(this HttpResponse response, CorrelationId correlationId) => | ||
response.Headers.Add(CorrelationIdHeaderName, new[] { correlationId.Value }); | ||
|
||
|
||
public static void SetCausationId(this HttpResponse response, CausationId causationId) => | ||
response.Headers.Add(CausationIdHeaderName, new[] { causationId.Value }); | ||
|
||
|
||
} |
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