AppSignal v0.7.1 Appsignal.Helpers
Helper functions and macros to instrument function calls.
Summary
Functions
Execute the given function in start / finish event calls. See instrument/6
Execute the given function in start / finish event calls. See instrument/6
Execute the given function in start / finish event calls
Macros
Instrument single functions
Automatically instrument all function definitions in the nested block
Automatically instrument all function definitions in the nested block using a given category
Types
Functions
instrument(instrument_arg, String.t, String.t, function) :: any
Execute the given function in start / finish event calls. See instrument/6
.
instrument(instrument_arg, String.t, String.t, String.t, function) :: any
Execute the given function in start / finish event calls. See instrument/6
.
instrument(instrument_arg, String.t, String.t, String.t, integer, function) :: any
Execute the given function in start / finish event calls.
The result of the function’s execution is returned. For example, to instrument a backend HTTP call in a Phoenix controller, do the following:
import Appsignal.Helpers, only: [instrument: 4]
def index(conn, _params) do
result = instrument(conn, "net.http", "Some slow backend call", fn() ->
Backend.get_result()
end
json conn, result
end
Macros
Instrument single functions
This macro allows you to define functions that are automatically
instrumented, by writing instrument_def
instead of def
when
defining the function:
defmodule SomeModule do import Appsignal.Helpers, only: [instrument_def: 2]
instrument_def expensive_method(_arg) do
# calculations...
end end
Automatically instrument all function definitions in the nested block
See instrumented/2
Automatically instrument all function definitions in the nested block using a given category
All def
statements that are passed in into the macro are
transformed to call Appsignal.Helpers.instrument/6
automatically.
defmodule MyInstrumentedModule do
import Appsignal.Helpers
instrumented do
def bar(arg) do
# code to be instrumented
end
# more functions...
end
end
Whenever MyInstrumentedModule.bar()
is called now, it will be
using instrument/6
to record an Appsignal event. The name of the
event is the same as the function name. When a category (atom) is
given, the category is postfixed to the function name, so given the
following code:
instrumented :http do
def load_data(arg) do
# code to be instrumented
end
end
events will be recorded under the event name load_data.http
whenever load_data()
is called.