Middleware
MIddleware can be added between when the message is read from a transport and before it is dispatched to handlers.
Uses in telemetry
Telemetry providers like AWS Xray, New Relic, Data Dog, etc can all be used to profile and report message processing times by using middleware.
This is useful to troubleshoot low message processing rates and identify message types that are taking the longest to process and would benefit from performance tuning.
The following shows how to integrate AWS Xray to profile how messages are handled.
Uses in logging context
Middleware is also useful when adding context of the message handling scope to each log produced in the handling cycle.
An example of this is appending a message's correlationId
to the metadata of each log. This can be done by using async_hooks that attach data to the promise scope that can be accessed by any logging request inside of it.
Last updated