TelemetryChildInit

Add telemetry events to your supervisors to track child startup times.

Installation

The package can be installed by adding telemetry_child_init to your list of dependencies in mix.exs:

def deps do
  [
    {:telemetry_child_init, "~> 0.1.0"}
  ]
end

Usage

Instrument your supervisor:

defmodule DummySupervisor do
  use Supervisor

  def start_link(init_arg) do
    Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
  end

  @impl true
  def init(_init_arg) do
    children =
      [{DummyChild, []}]
      |> TelemetryChildInit.instrument(__MODULE__)

    Supervisor.init(children, strategy: :one_for_one)
  end
end

Collect telemetry events

:telemetry_test.attach_event_handlers(self(), [
  [:supervisor, :startup, :start],
  [:supervisor, :startup, :stop],
  [:supervisor, :child, :init, :start],
  [:supervisor, :child, :init, :stop],
  [:supervisor, :child, :init, :exception]
])

Telemetry Events

The following Events are emitted

The following chart shows which metadata you can expect for each event:

event measures metadata
[:supervisor, :startup, :start]:system_time, :monotonic_time:supervisor_module, :ref
[:supervisor, :startup, :stop]:duration, :monotonic_time:supervisor_module, :ref
[:supervisor, :child, :init, :start]:system_time, :monotonic_time:telemetry_span_context, :supervisor_module, :ref, :module
[:supervisor, :child, :init, :stop]:duration, :monotonic_time:telemetry_span_context, :supervisor_module, :ref, :function
[:supervisor, :child, :init, :exception]:duration, :monotonic_time:telemetry_span_context, :supervisor_module, :ref, :module, :function, :kind, :reason, :stacktrace

Metadata

For :exception events the metadata also includes details about what caused the failure. The :kind value is determined by how an error occurred. Here are the possible kinds: