Moleculer has a built-in metrics feature. You can enable it within the broker options with metrics: true option.
If it is enabled, the broker emits metrics events at every requests. You can subsribe to these events in your services and transfer them to your Tracer system (ZipKin, OpenTracing…etc).
Context params & meta
You can customize that the broker puts some ctx.meta and ctx.params fields to the metrics events.
Define it in the action definition:
module.exports = { |
If the value is true, it adds all fields. If Array, it adds only the specified fields. If Function, it calls with params or metaand you need to return an Object.
Examples
All fields
// Action definition |
Only selected fields
// Action definition |
Custom mapping function
// Action definition |
Request started event
The broker emits an metrics.trace.span.start event when a new request is started.
The payload looks like the following:
{ |
Request finished event
The broker emits an metrics.trace.span.finish event when the call/request is finished.
The payload looks like the following:
{ |
Circuit-breaker events
metrics.circuit-breaker.opened
The broker sends this event when the circuit breaker module changed its state to open.
Payload
| Name | Type | Description |
|---|---|---|
nodeID |
String |
Node ID |
action |
String |
Action name |
failures |
Number |
Count of failures |
metrics.circuit-breaker.half-opened
The broker sends this event when the circuit breaker module changed its state to half-open.
Payload
| Name | Type | Description |
|---|---|---|
nodeID |
String |
Node ID |
action |
String |
Action name |
metrics.circuit-breaker.closed
The broker sends this event when the circuit breaker module changed its state to closed.
Payload
| Name | Type | Description |
|---|---|---|
nodeID |
String |
Node ID |
action |
String |
Action name |