Telemetry v0.2.0 Telemetry View Source
Telemetry
allows you to invoke certain functions whenever a particular event is emitted.
For more information see the documentation for attach/5
, attach_many/5
and execute/3
.
Link to this section Summary
Functions
Attaches the handler to the event
Attaches the handler to many events
Removes the existing handler
Emits the event, invoking handlers attached to it
Returns all handlers attached to events with given prefix
Link to this section Types
Link to this section Functions
attach( handler_id(), event_name(), module(), function :: atom(), config :: term() ) :: :ok | {:error, :already_exists}
Attaches the handler to the event.
handler_id
must be unique, if another handler with the same ID already exists the
{:error, :already_exists}
tuple is returned.
See execute/3
to learn how the handlers are invoked.
attach_many( handler_id(), [event_name()], module(), function :: atom(), config :: term() ) :: :ok | {:error, :already_exists}
Attaches the handler to many events.
The handler will be invoked whenever any of the events in the event_names
list is emitted. Note
that failure of the handler on any of these invokations will detach it from all the events in
event_name
(the same applies to manual detaching using detach/1
).
detach(handler_id()) :: :ok | {:error, :not_found}
Removes the existing handler.
If the handler with given ID doesn’t exist, {:error, :not_found}
is returned.
execute(event_name(), event_value(), event_metadata()) :: :ok
Emits the event, invoking handlers attached to it.
When the event is emitted, module.function
provided to attach/5
is called with four arguments:
- the event name
- the event value
- the event metadata
- the handler configuration given to
attach/5
All the handlers are executed by the process calling this function. If the function fails (raises, exits or throws) then the handler is removed.
Note that you should not rely on the order in which handlers are invoked.
list_handlers(event_prefix()) :: [ {handler_id(), event_name(), module(), function :: atom(), config :: term()} ]
Returns all handlers attached to events with given prefix.
Handlers attached to many events at once using attach_many/5
will be listed once for each
event they’re attached to.
Note that you can list all handlers by feeding this function an empty list.