A function decorator for telemetry.
defmodule MyApp.MyModule do
use TelemetryDecorator
@decorate telemetry([:my_app, :succeed])
def succeed(arg1, arg2) do
:...
end
end
Because we're using :telemetry.span/3
under the hood, you'll get these events:
[:my_app, :succeed, :start]
[:my_app, :succeed, :stop]
[:my_app, :succeed, :exception]
Because we're wrapping it with Decorator
, we can provide more metadata than
:telemetry.span/3
usually does:
-
Any variables matched by your arguments for
:start
,:stop
, and:exception
events -
Your function's
result
for:stop
events (overriding any variable namedresult
)
To include more internal variables in your :stop
events, add the include
option:
defmodule MyApp.MyModule do
use TelemetryDecorator
def succeed(why), do: succeed(why, [])
@decorate telemetry([:my_app, :succeed], include: [:type])
def succeed(why, opts) do
type = Keyword.get(opts, :type, :ok)
{type, why}
end
end
To watch :telemetry.span/3
style events at the iex>
prompt:
handler_id = TelemetryDecorator.watch([:my_app, :succeed])
MyApp.MyModule.succeed(42)
# hang up, or explicitly unwatch:
TelemetryDecorator.unwatch(handler_id)
TelemetryDecorator.watch/1
sends to remote consoles, too, and with syntax colours. See the
documentation for Pretty
to find out how.
Add telemetry_decorator
to your list of dependencies in mix.exs
:
def deps do
[
{:telemetry_decorator, "~> 1.0.0"}
]
end
make check
before you commit! If you'd prefer to do it manually:
mix do deps.get, deps.unlock --unused, deps.clean --unused
if you change dependenciesmix compile --warnings-as-errors
for a stricter compilemix coveralls.html
to check for test coveragemix credo
to suggest more idiomatic style for your codemix dialyzer
to find problems typing might reveal… albeit slowlymix docs
to generate documentation