Send metrics and events from Ruby and Rails apps to Honeybadger Insights
Automatic instrumentation
Section titled “Automatic instrumentation”Honeybadger
automatically instruments your Ruby and Rails application
to send events to Insights: web requests, database queries, background jobs
(ActiveJob, Sidekiq, SolidQueue), cache operations, outbound HTTP requests, and
more. This is the easiest way to get started with Insights. In version 6.0 and
later of the honeybadger gem, it’s enabled by default: once you’ve
installed the gem, there’s nothing
else to set up.
For older versions (v5.11+), enable Insights in your honeybadger.yml
configuration file:
insights: enabled: trueSee Automatic instrumentation to learn which events are captured and how to turn off individual plugins, and the Ruby event reference for each event’s fields.
Sending your logs to Insights is a quick way to get some visibility into your app. There are two good options:
Semantic Logger
Section titled “Semantic Logger”Use the
rails_semantic_logger gem
and enable the HoneybadgerInsights appender by adding
config.semantic_logger.add_appender(appender: :honeybadger_insights) to
config/application.rb. Outside of Rails, you can use the same appender with
the semantic_logger gem.
Please note that if you are using SolidQueue, you will need to add the following
snippet to config/initializers/solid_queue.rb to work around a
known issue with Semantic Logger
that causes SolidQueue/ActiveJob logging to not be sent to Insights:
# Re-open appenders after forking the worker, dispatcher, and scheduler processesSolidQueue.on_worker_start { SemanticLogger.reopen }SolidQueue.on_dispatcher_start { SemanticLogger.reopen }SolidQueue.on_scheduler_start { SemanticLogger.reopen }Lograge
Section titled “Lograge”Use Lograge to emit JSON-formatted output
to your log files and Vector to
forward them to Insights. If you go
this route, be sure to disable the log tagging in your Rails environment config
(config/environments/production.rb) by commenting out the config.log_tags
line, as that will mess with the JSON output.
Metrics
Section titled “Metrics”You can get more details about what’s happening in your application by enabling our gem’s automatic instrumentation, which will report information about every SQL query, HTTP request, etc. to Insights. This will consume more Insights quota than the logging approach, but you will get much more data to use for analyzing your app’s performance, and this will populate our ready-made Rails dashboard, which includes charts for request duration, SQL query counts, and more. More information can be found here.
Alternatively, you can use Yabeda and our Yabeda integration to collect and report metrics in your Ruby and Rails apps. Several default metrics, such as request counts, request duration, etc., will be reported automatically once you’ve added and configured the gems.
Events
Section titled “Events”If you have custom events you’d like to track, use Honeybadger#event to report
those events to Insights:
class AccountsController < ApplicationController def create # Account.create(...) Honeybadger.event("Created account", account_id: account.id, account_name: account.name, plan: account.subscription.name) endendMore information about sending events to Insights from your Ruby and Rails apps can be found here.