Surgex v3.2.7 Surgex.Appsignal.EctoLogger View Source

Integration for logging Ecto queries.

This is an override of Appsignal.Ecto - backwards compatible with the original but with additional options available in the handle_event/4 function.

Link to this section Summary

Functions

Handles Ecto event generated via Telemetry

Logs the event via Ecto logger instead of Telemetry (Ecto before version 3.0)

Link to this section Functions

Link to this function handle_event(telemetry_event, latency, metadata, config) View Source

Handles Ecto event generated via Telemetry.

This is an override of Appsignal.Ecto.handle_event/4 - backwards compatible with the original but with additional options controlled via Telemetry configuration list.

Options

  • :event_name - allows to adjust logged event name and include app name/repo name in it. The value passed may be string literal or list of event name parts which may include string literals or following special atoms:

    • :app - name of app that owns specific Ecto repo
    • :repo - name of the specific Ecto repo
    • :method - Ecto method (currently just “query”)
  • :query_stages - allows to alter the default duration calc behavior in which all three Ecto stages (:queue, :query and :decode) are included in the event. The optimal scenario would be to track these separately but Appsignal NIF currently doesn’t give an option to log multiple events backwards in time so this option allows to exclude some of these stages and/or configure multiple events for specific stages. You can set this option to list of stages that should be included or to :all atom which will result in generating both the ecto event for whole event and separate ecto_<stage> subevents for each stage.

Examples

Multiple repos:

# lib/my_app/application.ex

Telemetry.attach_many(
  "my-app-ecto-appsignal",
  [
    [:my_app, :some_repo, :query],
    [:my_app, :other_repo, :query]
  ],
  Surgex.Appsignal.EctoLogger,
  :handle_event,
  event_name: ["ecto", :repo, :method]
)

Multiple apps eg. in Umbrella:

# apps/some_app/lib/some_app/application.ex

Telemetry.attach(
  "some-app-ecto-appsignal",
  [:some_app, :repo, :query],
  Surgex.Appsignal.EctoLogger,
  :handle_event,
  event_name: ["ecto", :app, :method]
)

# apps/other_app/lib/other_app/application.ex

Telemetry.attach(
  "other-app-ecto-appsignal",
  [:other_app, :repo, :query],
  Surgex.Appsignal.EctoLogger,
  :handle_event,
  event_name: ["ecto", :app, :method]
)

All stages logged together with main event:

# lib/my_app/application.ex

Telemetry.attach(
  "my-app-ecto-appsignal",
  [:my_app, :repo, :query],
  Surgex.Appsignal.EctoLogger,
  :handle_event,
  event_name: ["ecto", :method],
  queue_stages: :all
)

Customization of the above - additional log for queue time without query and decode times:

# lib/my_app/application.ex

Telemetry.attach(
  "my-app-ecto-appsignal",
  [:my_app, :repo, :query],
  Surgex.Appsignal.EctoLogger,
  :handle_event,
  event_name: ["ecto", :method]
)

Telemetry.attach(
  "my-app-ecto-appsignal-queue",
  [:my_app, :repo, :query],
  Surgex.Appsignal.EctoLogger,
  :handle_event,
  event_name: ["ecto_queue", :method],
  query_stages: [:queue]
)

Logs the event via Ecto logger instead of Telemetry (Ecto before version 3.0).

This is an override of Appsignal.Ecto.log/1 - backwards compatible with the original but with additional control over event name and query stages that are included in event duration both of which are used by handle_event/4.