Canonical Logs

Inspired by the legendary Stripe blog post, this library consolidates your Plug/Phoenix/Absinthe request logs into a single log line with all of their relevant information for easier querying.

Installation

Add canonical_logs to your list of dependencies in mix.exs:

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

Usage

In your application.ex, add the following to the top of your start/2 function:

  CanonicalLogs.attach()

or

  CanonicalLogs.attach(
    conn_metadata: [:request_path, :method, :status, :params]
    filter_metadata_recursively: []
  )

Canonical Logs is built off of Plug.Telemetry events. If you use Phoenix, you'll find it called in your <APP_NAME>Web.Endpoint module.

Wherever the plug is used, modify the line to add the option log: false, like so:

  plug(Plug.Telemetry, event_prefix: [:phoenix, :endpoint], log: false)

That's it! There's configuration options and more in the docs.

Absinthe

CanonicalLogs.Absinthe is included to allow providing the GraphQL operation name and variables as metadata. Just after CanonicalLogs.attach/1, add:

  CanonicalLogs.Absinthe.attach()

Additionally, it would make sense to update the :conn_metadata configuration to not include :params.

Configuration

Todo