AppSignal v0.3.0 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

Automatically instrument all function definitions in the nested block

Automatically instrument all function definitions in the nested block using a given category

Types

instrument_arg ::
  Appsignal.Transaction.t |
  Plug.Conn.t |
  pid

Functions

instrument(arg, name, title, function)

Specs

instrument(instrument_arg, String.t, String.t, function) :: any

Execute the given function in start / finish event calls. See instrument/6.

instrument(arg, name, title, body, function)

Specs

instrument(instrument_arg, String.t, String.t, String.t, function) :: any

Execute the given function in start / finish event calls. See instrument/6.

instrument(pid, name, title, body, body_format, function)

Specs

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

instrumented(code)

Automatically instrument all function definitions in the nested block

See instrumented/2

instrumented(category, code)

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.