Should I use Request-Id, X-Request-Id or X-Correlation-Id in the request header?

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 ( ) 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?

2 Answers

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.

  1. Install Microsoft.ApplicationInsights.AspNetCore
  2. Configure WebHost.CreateDefaultBuilder(args).UseStartup<Startup>().UseApplicationInsights()
  3. Use like var activity = Activity.Current;
1

For X-Request-id, I simply used a unique id and boom, my issue was solved.

In Axios.

const options = { method: 'POST', url: 'myurl', headers: { 'content-disposition': 'always', 'X-REQUEST-ID': Math.random(200) }, data: { amount: { currency: 'USD', number: 1 }, }; 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like