0.0.1 • Published 3 years ago
moleculer-correlation v0.0.1

moleculer-correlation 
Log correlation for Moleculer via AsyncLocalStorage
Features
Adds the current context's requestID to any log messages made while the context is available. Takes
advantage of Node 14+ AsyncStorage.
Install
npm install moleculer-correlation --saveUsage
const { ServiceBroker } = require("moleculer");
const { CorrelationMiddleware } = require("moleculer-correlation");
const broker = new ServiceBroker({
middlewares: [CorrelationMiddleware]
});
// --- SERVICE ---
broker.createService({
name: "greeter",
actions: {
hello: {
handler(ctx) {
this.logger.info("Creating a Greeting")
return `Hello ${ctx.params.name}`;
}
}
}
});
// --- TEST ---
broker.start()
.then(() => broker.call("greeter.hello").then(res => broker.logger.info(res)))
// --- CONTEXT REQUEST ID IN LOGS WHEN AVAILABLE ---
// [2022-06-09T03:18:02.291Z] INFO node/GREETER: [2e524af4-69a1-440f-9a1d-1904a6b28258] Creating a GreetingTest
$ npm testIn development with watching
$ npm run ciContribution
Please send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.
License
The project is available under the MIT license.
Contact
Copyright (c) 2022 Adam McCormick
0.0.1
3 years ago