Skip to content
Helpers for adding/reading x-request-id header from client/server applications
C#
Branch: master
Clone or download
BrianSkibinski Merge pull request #1 from JCapriotti/master
Update to .NET Standard 1.3 and 2.0
Latest commit 834639c May 27, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
RequestCorrelation.Net
.gitattributes
.gitignore Initial Check-in Sep 16, 2015
LICENSE
README.md

README.md

RequestCorrelation

RequestCorrelation is a grouping of projects that will allow adding and receiving a request correlation header in x-request-id. It is useful for tracing/logging across services so that you can correlate requests to responses in a multi-service environment (microservices/soa).

Currently we only have two libraries, one for regular .net and one that extends RestSharp. They don't depend on each other so you can use either/both.

#Install Get it from nuget:

PM> Install-Package RequestCorrelation.Net

OR

PM> Install-Package RequestCorrelation.Net.RestSharp

Usage:

All of the GetRequestId methods will return the header if present and a Guid, otherwise will return a new randomly generated Guid using Guid.NewGuid. Any x-request-id header that can be parsed by Guid.TryParse will be returned. If you need to know if the header was there, use the TryGetRequestId methods.

Adding the RequestId to a WebRequest

var request = WebRequest.Create("http://localhost/");
request.AddRequestId(Guid.NewGuid());

Adding the RequestId to a RestSharp

var request = new RestRequest("http://localhost");
request.AddRequestId(Guid.NewGuid());

Getting the RequestId or a new Guid on the Server

Guid id = HttpContext.Current.GetRequestId()

Getting the RequestId on the Server

Guid id = Guid.Empty;
if (HttpContext.Current.TryGetRequestId(out id))
{
//use it
} else { 
//do something else
}

Getting the RequestId on the Server in MVC (works the same way in WebApi)

[HttpGet]
public virtual ActionResult Index()
{
	var requestId = Request.GetRequestId();
	...
}

#Known issues: We're only building a .Net 4.5 version right now but there's not really a reason it couldn't support others. I accept pull requests :)

You can’t perform that action at this time.