stacked-request-id-provider
v2.2.0
Published
Builds a stacked request id for logging across micro-services.
Downloads
13
Readme
stacked-request-id-provider
Utility for building stacked request ids. Given an express request, it generates a new id for the current request, and pushes it to the stack defined by X-Request-Id. The full id is assigned to req.id
Thanks to Brandur for describing it better than I ever could: https://brandur.org/request-ids#multiple
For example, if request has no X-Request-ID header,
var StackedRequestIdProvider = require( 'stacked-request-id-provider' );
var provider = new StackedRequestIdProvider();
var req: {
headers: {}
}
var requestId = provider.getRequestId( req );
// requestId = [ {uuid} ]
If the request has a single X-Request-ID value,
var StackedRequestIdProvider = require( 'stacked-request-id-provider' );
var provider = new StackedRequestIdProvider();
var req: {
headers: { 'x-request-id': 'ABC' }
}
var requestId = provider.getRequestId( req );
// requestId = [ {uuid}, 'ABC' ]
If the request has a multiple X-Request-ID values,
var StackedRequestIdProvider = require( 'stacked-request-id-provider' );
var provider = new StackedRequestIdProvider();
var req: {
headers: { 'x-request-id': 'ABC,XYZ' }
}
var requestId = provider.getRequestId( req );
// requestId = [ {uuid}, 'ABC', 'XYZ' ]