telemetry_wrappers v0.1.0 TelemetryWrappers
Documentation for TelemetryWrappers.
Link to this section Summary
Functions
Defines a function that will have its execution time measured and sent as a telemetry event.
Defines a private function that will have its execution time measured and sent as a telemetry event.
Link to this section Functions
deftimed(function_name, metric_name \\ [], list) (macro)
Defines a function that will have its execution time measured and sent as a telemetry event.
As an example you can define the following module
defmodule TelemetryWrappers.Support.TestModule do
use TelemetryWrappers
deftimed timed_function(a, b), [:a, :b] do
a + b
end
deftimed timed_function2(a, b) do
a + b
end
end
Then both functions will work as expected:
iex> TelemetryWrappers.Support.TestModule.timed_function(1, 2)
3
iex> TelemetryWrappers.Support.TestModule.timed_function2(1, 2)
3
but it will also emit a :telemetry
event [:a, :b]
with the contents %{call: timing}
where timing
is the time the function took to execute in microseconds.
The metric name is optional and will default to [:timing, name]
where name
is the name of the function (without arity).
Note that type specs can still be defined for function defined with deftimed
just as you would normally, e.g.
@spec timed_function(number(), number()) :: number()
deftimed timed_function(a, b), [:a, :b] do
a + b
end
deftimedp(function_name, metric_name \\ [], list) (macro)
Defines a private function that will have its execution time measured and sent as a telemetry event.
In principle, same as deftimed/3
but defines a private function instead.
As an example you can define the following module
defmodule TelemetryWrappers.Support.TestModule do
use TelemetryWrappers
def invoke_private(a) do
private_fun(a)
end
deftimedp(private_fun(a), [:something], do: a)
end
And then invoke the function:
iex> TelemetryWrappers.Support.TestModule.invoke_private(15)
15
which will also emit a :telemetry
event [:something]
with the contents %{call: timing}
where timing
is the time the function took to execute the private function in microseconds.
The metric name is optional and will default to [:timing, name]
where name
is the name of the function (without arity),
just like in deftimed/3