Phoenix

Integration Timber with the Phoenix framework

The Timber Phoenix integration requires installation of the base timber Hex package first.

Timber integrates with Phoenix through the timber_phoenix Hex package which automatically captures useful context and metadata, turning your Phoenix logs into rich structured events.

Installation

When integrating Timber with Phoenix for an umbrella application, the :timber_phoenix library needs to be a dependency for every application that defines a Phoenix endpoint.

  1. Ensure that you have both :timber (version 3.1.0 or later) and :timber_phoenix listed as dependencies in mix.exs:

    mix.exs
    def deps do
    [
    {:timber, "~> 3.1"},
    {:timber_phoenix, "~> 1.0"}
    ]
    end
  2. Run mix deps.get to get the dependencies.

  3. Add a configuration line for every Phoenix endpoint. For example, if you have the application :my_appand the Phoenix endpoint MyApp.Endpoint, the configuration in config/config.exs would look like this:

    config/config.exs
    use Mix.Config
    config :my_app, MyApp.Endpoint,
    # ...,
    instrumenters: [Timber.Phoenix],

For more information, see the documentation for the Timber.Ecto module.

Events

controller_called

The controller_called event is emitted when a controller received a request.

{
"controller_called": {
"controller": "MyController",
"action": "action",
"format": "html",
"params_json": "{\"key\":\"val\"}"
}
}

Name

Type

Description

controller_called.controller

string

The name of the controller receiving the call.

controller_called.action

float

The name of the controller action receiving the call.

controller_called.format

string

The format of the request such as html or json

controller_called.params_json

The parameters being sent to the controller encoded in JSON. See this guide on why we encode this data to JSON.

template_rendered

The template_rendered event is emitted when ActionView renders a template:

{
"template_rendered": {
"name": "/path/to/template.html.erb",
"duration_ms": 50.4
}
}

Name

Type

Description

template_rendered.name

string

The name of the template rendered.

template_rendered.duration_ms

float

The duration, in milliseconds, that it took to render the template.