mnr-transaction-id
v2.0.0
Published
Express middleware for tracking transactions in microservices architecture
Downloads
6
Maintainers
Readme
mnr-transaction-id
Express middleware for tracking transactions in microservices architecture.
You may not need it!
This is a custom, highly opinionated solution aimed at code reuse for a few private projects.
Installation
$ npm install --save mnr-transaction-id
Usage Example
JavaScript:
const mnrTransactionId = require('mnr-transaction-id');
const app = express();
app.use(mnrTransactionId);
app.get('/my-endpoint', (req, res) => {
console.log(req.transactionId);
});
TypeScript:
import mnrTransactionId, { RequestWithTransactionId } from 'mnr-transaction-id';
const app = express();
app.use(mnrTransactionId);
app.get('/my-endpoint', (req, res) => {
console.log((req as RequestWithTransactionId).transactionId);
});
What It Does
Add
req.transactionId
either from request'sx-transaction-id
HTTP header, or newly generated UUID if there is no such a header. The most obvious use case forreq.transactionId
is using it in logs.Add
x-transaction-id
HTTP header to response. The value is taken fromreq.transactionId
.