I am not clear which id header I should put in the request and response for the correlationship purpose.
"X-Correlation-ID" and the "X-Request-ID" are the known http header. Does it matter which one I use in the request and response?
ASP.NET Core's System.Diagnostics.DiagnosticSource looks for the "Request-Id". Is this for the Activity purpose only? Why doesn't it use the "X-Request-ID"?
If I don't use the Activity, I don't need to send that header, right?
ASP.NET Core also has the Hierarchical Request-Id (https://github.com/dotnet/corefx/blob/master/src/System.Diagnostics.DiagnosticSource/src/HierarchicalRequestId.md ) that I like the idea. I can do something like this
var newRequestId = $"{context.Request.headers["X-Correlation-ID"]}:{CreateNewGuid()}";
OR is it better to use the Activity? I find the Activity.Current is always null. Does it need to be enabled and does it affect performance?
Request and Response Client Application/User can pass the correlation ID for each RESTful API call through the HTTP header name: X-Correlation-ID. This Correlation ID will get returned in the response header, irrespective of the response status (Success or Fail).
When the caller processes the reply, it uses the request identifier to correlate the request with the reply. This is called a correlation identifier because of the way the caller uses the identifier to correlate each reply with the request. A correlation ID is usually put in the header of a message.
All POST, PUT, and PATCH HTTP requests should contain a unique X-Request-Id header which is used to ensure idempotent message processing in case of a retry. If you make it a random string, unique per request, it won't infringe on your privacy, nor enable tracking.
A Correlation ID can be defined as an 'identifier value attached to messages and request headers which allows referencing a particular transaction or event'.
For Request-Id
, it's uniquely identifies every HTTP request involved in operation processing, and is generated on the caller side and passed to callee.
For X-Correlation-ID
, also known as a Transit ID, is a unique identifier value that is attached to requests and messages that allow reference to a particular transaction or event chain.
For every request, you should use Request-Id
, for request transaction, you should use X-Correlation-ID
.
If I don't use the Activity, I don't need to send that header, right?
For Correlation ID, in general, you don’t have to use one. But if you are designing a distributed system that incorporates message queues and asynchronous processing, you will do well to include a Correlation ID in your messages.
I find the Activity.Current is always null. Does it need to be enabled and does it affect performance?
For using Activity.Current
, you need to able ApplicationInsights
, or implement your own feature to manage activity.
Microsoft.ApplicationInsights.AspNetCore
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().UseApplicationInsights()
var activity = Activity.Current;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With