Capturing Logs and Events

Honeybadger's Elixir package can be used to send events to Honeybadger Insights.

Automatic Instrumentation

Honeybadger Insights allows you to automatically track various events in your application. To enable Insights automatic instrumentation, add the following to your configuration:

elixir
config :honeybadger, insights_enabled: true

Honeybadger automatically instruments the following libraries when they are available:

  • Ecto: Database queries
  • Plug/Phoenix: HTTP requests
  • LiveView: Phoenix LiveView lifecycle events
  • Oban: Background job processing
  • Absinthe: GraphQL query execution
  • Finch: HTTP client requests, often used by other libraries like Req
  • Tesla: HTTP client requests

Instrumented Libraries

Each instrumented library has its own configuration options. You can customize the telemetry events that are captured, as well as the data that is sent to Honeybadger.


Ecto

Captures database query telemetry events from Ecto repositories.

Default Configuration

By default, this module listens for telemetry events from all configured Ecto repositories. It reads the :ecto_repos configuration to identify repositories and their telemetry prefixes:

elixir
config :honeybadger, ecto_repos: [MyApp.Repo]

Custom Configuration

You can customize this module's behavior with the following configuration options:

elixir
config :honeybadger, insights_config: %{ ecto: %{ # Disable Ecto telemetry events disabled: false, # A list of strings or regex patterns of queries to exclude excluded_queries: [ ~r/^(begin|commit)( immediate)?( transaction)?$/i, ~r/SELECT pg_notify/, ~r/schema_migrations/ ], # Format & include the stacktrace with each query. You must also # update your repo config to enable: # # config :my_app, MyApp.Repo, # stacktrace: true # # Can be a boolean to enable for all or a list of sources to enable. include_stacktrace: true # Alternative source whitelist example: # include_stacktrace: ["source_a", "source_b"], # Format & include the query parameters with each query. Can be a # boolean to enable for all or a list of sources to enable. include_params: true # Alternative source whitelist example: # include_params:["source_a", "source_b"], # A list of table/source names to exclude excluded_sources: [ "schema_migrations", "oban_jobs", "oban_peers" ] } }

By default, transaction bookkeeping queries and schema migration checks are excluded, as well as queries to common background job tables.


Plug/Phoenix

Captures telemetry events from HTTP requests processed by Plug and Phoenix.

Default Configuration

By default, this module listens for the standard Phoenix endpoint telemetry event:

phoenix.endpoint.stop

This is compatible with the default Phoenix configuration that adds telemetry via Plug.Telemetry:

plug Plug.Telemetry, event_prefix: [:my, :prefix]

Custom Configuration

You can customize the telemetry events to listen for by updating the insights_config:

elixir
config :honeybadger, insights_config: %{ plug: %{ # Disable Plug/Phoenix telemetry events disabled: false, telemetry_events: [[:my, :prefix, :stop]] } }


LiveView

Captures telemetry events from Phoenix LiveView.

Default Configuration

By default, this module listens for the following LiveView telemetry events:

phoenix.live_view.mount.stop phoenix.live_view.handle_params.stop phoenix.live_view.handle_event.stop

phoenix.live_component.update.stop phoenix.live_component.handle_event.stop

Custom Configuration

You can customize the telemetry events to listen for by updating the insights_config:

elixir
config :honeybadger, insights_config: %{ live_view: %{ # Disable LiveView telemetry events disabled: false, telemetry_events: [ [:phoenix, :live_view, :mount, :stop], [:phoenix, :live_component, :handle_event, :stop], [:phoenix, :live_component, :update, :stop] [:phoenix, :live_view, :handle_event, :stop], [:phoenix, :live_view, :handle_params, :stop], [:phoenix, :live_view, :update, :stop] ] } }


Oban

Captures telemetry events from Oban job processing.

Default Configuration

By default, this module listens for the following Oban telemetry events:

oban.job.stop oban.job.exception

Custom Configuration

You can customize the telemetry events to listen for by updating the insights_config:

elixir
config :honeybadger, insights_config: %{ oban: %{ # Disable Oban telemetry events disabled: false, telemetry_events: [ [:oban, :job, :stop], [:oban, :job, :exception], [:oban, :engine, :start] ] } }


Absinthe

Captures telemetry events from GraphQL operations executed via Absinthe.

Default Configuration

By default, this module listens for the following Absinthe telemetry events:

absinthe.execute.operation.stop absinthe.execute.operation.exception

Custom Configuration

You can customize the telemetry events to listen for by updating the insights_config:

elixir
config :honeybadger, insights_config: %{ absinthe: %{ # Disable Absinthe telemetry events disabled: false, telemetry_events: [ [:absinthe, :execute, :operation, :stop], [:absinthe, :execute, :operation, :exception], [:absinthe, :resolve, :field, :stop] ] } }

Note that adding field-level events like "absinthe.resolve.field.stop" can significantly increase the number of telemetry events generated.


Finch

Captures telemetry events from HTTP requests made using Finch.

Default Configuration

By default, this module listens for the standard Finch request telemetry event:

finch.request.stop

Custom Configuration

You can customize the telemetry events to listen for by updating the insights_config:

elixir
config :honeybadger, insights_config: %{ finch: %{ # Disable Finch telemetry events disabled: false, telemetry_events: ["finch.request.stop", "finch.request.exception"], # Include full URLs in telemetry events (default: false - only hostname is included) full_url: false } }

By default, only the hostname from URLs is captured for security and privacy reasons. If you need to capture the full URL including paths (but not query parameters), you can enable the full_url option.


Default Configuration

By default, this module listens for the standard Tesla request telemetry events:

tesla.request.stop tesla.request.exception

Custom Configuration

This module can be configured in the application config:

elixir
config :honeybadger, insights_config: %{ tesla: %{ # Disable Tesla telemetry events disabled: false, # Include full URLs in telemetry events (default: false - only hostname is included) full_url: false, # Custom telemetry event patterns to listen for (optional) telemetry_events: [ [:tesla, :request, :stop], [:tesla, :request, :exception] ] } }

Job event context

We attempt to automatically inject request_id and any other event context into events emitted from a Job. The method for inheriting event context might not work in all cases, so you can explicitly add event context to a job by using the add_event_context/1 function:

elixir
MyApp.Worker.new() |> Honeybadger.Insights.Oban.add_event_context() |> Oban.insert()

Ensure that the event context is avaliable in the caller's process dictionary before inserting into the job.

Manually Sending Events

Use the Honeybadger.event/1 function to send event data to the events API. A ts field with the current timestamp will be added to the data if it isn't provided. You can also use Honeybadger.event/2, which accepts a string as the first parameter and adds that value to the event_type field in the map before being sent to the API.

elixir
Honeybadger.event(%{ event_type: "user_created", user: user.id }) Honeybadger.event("project_deleted", %{ project: project.name })

Sending logs from your infrastructure

Honeybadger isn't just for errors and application data! You can use our syslog, Vector, or PaaS integrations to send additional data from your infrastructure to Honeybadger Insights, where you can query, visualize, and analyze all of your production data in one place.