Send metrics and events from Ruby and Rails apps to Honeybadger Insights

Logs

Sending your logs to Insights is a quick way to get some visibility into your app. There are two good options:

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:

yaml
# Re-open appenders after forking the worker, dispatcher, and scheduler processes SolidQueue.on_worker_start { SemanticLogger.reopen } SolidQueue.on_dispatcher_start { SemanticLogger.reopen } SolidQueue.on_scheduler_start { SemanticLogger.reopen }
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

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. 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

If you have custom events you'd like to track, use Honeybadger#event to report those events to Insights:

ruby
# app/controllers/accounts_controller.rb class AccountsController < ApplicationController def create # Account.create(...) Honeybadger.event("Created account", account_id: account.id, account_name: account.name, plan: account.subscription.name) end end

More information about sending events to Insights from your Ruby and Rails apps can be found here.