PlugInstrumenter v0.1.2 PlugInstrumenter View Source
Reports plug timing to a configurable callback function.
Wraps plugs, adding instrumentation. Use it in your plug pipeline like this:
plug PlugInstrumenter, plug: MyPlug
Pass options to the plug like this:
plug PlugInstrumenter, plug: MyPlug, opts: [my_opt: :cool]
Metrics are passed to a configured callback, and a configurable name where the default is based on the module’s name. There are three phases that can be instrumented:
:pre
- when thecall/2
function is executed.:post
- when thebefore_send
callbacks are executed.:init
- when theinit/1
function is executed.
Options
Options can be set in your configuration under the :plug_instrumenter
namespace. They will be overridden by options passed to the plug
macro.
:plug
- The plug to instrument:now
- a module/function tuple pointing to an mfa that returns the current time. Default is:erlang.monotonic_time(:microsecond)
.:callback
- The instrumentation callback, which should have a 3-arity function. The default callback callsLogger.debug
. The arguments passed to the function are as follows:phase
- one of::init
- executed after theinit/1
has completed:pre
- executed after thecall/2
method has completed:post
- executed after before_send callbacks have completed
{start, finish}
- the start and finish time, as reported by:now
opts
the PlugInstrumenter options represented as a map.
:name
- a string or 2-arity function that returns the metric name as a string. If a function is used, it will be called during the plug’s init phase with the following arguments:module
- The name of the plug moduleopts
- The options passed to the plug instrumenter. The instrumented plug’s options are included via the key:plug_opts
.