AppSignal - Transactions

the post is about using AppSignal transactions in Elixir project but most basic ideas stay the same in Ruby/Rails project.


  1. https://docs.appsignal.com/elixir/instrumentation/instrumentation.html
  2. https://github.com/appsignal/appsignal-elixir/issues/299

transaction is created automatically for HTTP requests only (when Phoenix integration is set up) - all workers must start transaction manually using function decorators or corresponding helper functions:

defmodule MyApp.Worker
  use Appsignal.Instrumentation.Decorators

  @decorate transaction(:background_job)
  def call do
    # ...
  end
end

NOTE: if AppSignal is disabled (active option is set to false - say, in development), transaction is never started - silently, without warnings.

if AppSignal transaction is not started (say, in GenServer):

transactions and child processes

information about current transaction is lost in child processes!

defmodule Worker do
  @decorate transaction(:background_job)
  def perform do
    IO.inspect(Appsignal.TransactionRegistry.lookup(self()))
    # => AppSignal.Transaction{o1m4adl8kaao0}
    task = Task.async(fn ->
      IO.inspect(Appsignal.TransactionRegistry.lookup(self()))
      # => nil
    end)

    Task.await(task)
  end
end

there are 2 solutions to use AppSignal in child processes (to add custom instrumentation and set errors):

tips