AppSignal v1.5.0 Appsignal.Phoenix.Channel View Source

Instrumentation for channel events

Instrumenting a channel’s handle_in/3

Currently, incoming channel requests can be instrumented, by adding code to the handle_in function of your application. We use function decorators to minimize the amount of code you have to add to your channel.

defmodule SomeApp.MyChannel do
  use Appsignal.Instrumentation.Decorators

  @decorate channel_action
  def handle_in("ping", _payload, socket) do
    # your code here..
  end
end

Channel events will be displayed under the “Background jobs” tab, showing the channel module and the action argument that you entered.

Adding channel payloads

Channel payloads aren’t included by default, but can be added by using Appsignal.Transaction.set_sample_data/2 using the “params” key:

defmodule SomeApp.MyChannel do
  use Appsignal.Instrumentation.Decorators

  @decorate channel_action
  def handle_in("ping", payload, socket) do
    Appsignal.Transaction.set_sample_data(
      "params", Appsignal.Utils.ParamsFilter.filter_values(payload)
    )

    # your code here..
  end
end

Instrumenting without decorators

You can also decide not to use function decorators. In that case, use the channel_action/4 function directly, passing in a name for the channel action, the socket and the actual code that you are executing in the channel handler:

defmodule SomeApp.MyChannel do
  import Appsignal.Phoenix.Channel, only: [channel_action: 4]

  def handle_in("ping" = action, _payload, socket) do
    channel_action(__MODULE__, action, socket, fn ->
      # do some heave processing here...
      reply = perform_work()
      {:reply, {:ok, reply}, socket}
    end)
  end
end

Adding channel payloads

To add channel payloads, use channel_action/5:

defmodule SomeApp.MyChannel do
  import Appsignal.Phoenix.Channel, only: [channel_action: 5]

  def handle_in("ping" = action, payload, socket) do
    channel_action(__MODULE__, action, socket, payload, fn ->
      # do some heave processing here...
      reply = perform_work()
      {:reply, {:ok, reply}, socket}
    end)
  end
end

Link to this section Summary

Functions

Record a channel action. Meant to be called from the ‘channel_action’ instrumentation decorator

Given the Appsignal.Transaction and a Phoenix.Socket, add the socket metadata to the transaction

Link to this section Functions

Link to this function channel_action(module, name, socket, function) View Source
channel_action(atom(), String.t(), Phoenix.Socket.t(), (... -> any())) :: any()

Record a channel action. Meant to be called from the ‘channel_action’ instrumentation decorator.

Link to this function channel_action(module, name, socket, params, function) View Source
channel_action(atom(), String.t(), Phoenix.Socket.t(), map(), (... -> any())) :: any()

Given the Appsignal.Transaction and a Phoenix.Socket, add the socket metadata to the transaction.