serilog-contrib / serilog-enrichers-clientinfo

Enrich logs with client IP, correlation id and HTTP request headers.
MIT License
93 stars 20 forks source link

Passing correlation id to HttpClient #28

Closed sergiojrdotnet closed 12 months ago

sergiojrdotnet commented 12 months ago

Is there any suggestion about how can I get and pass the current correlation id through HttpClient's from HttpClientFactory? My objective is to propagate the current value to subsequent microservices.

mo-esmp commented 12 months ago

Correlation id would be cached in HttpContext.Items as LogEventProperty and you can use it to get value.

var logEventProperty =  HttpContext.Items["CorrelationId"] as LogEventProperty;
var correlationId = logEventProperty.Properties["CorrelationId"].LiteralValue().ToString();