Upgrade from AppSignal for Ruby gem 3.x to 4.x
AppSignal for Ruby 4.0 is a major release that introduces multiple error support, amendable sample data, changes to how it instruments other gems, how custom instrumentation works, and the removal of previously deprecated modules. Follow this guide to make the upgrade process smoother.
Upgrade to the latest 3.x series
Before upgrading to AppSignal for Ruby gem 4.0, upgrade to the latest gem from the 3.x series. This version will print and log deprecation warnings for things that were removed in version 4.x of the Ruby gem. Run the tests for your app the gem is integrated with and fix any deprecation warnings and errors you may encounter.
First, in the app's Gemfile, update the version lock to ~> 3.0 and run bundle update appsignal in a terminal in the same directory as the Gemfile.
# Gemfile gem "appsignal", "~> 3.0"
Run your applications and fix any deprecation warnings printed to the application's STDERR output and logged in appsignal.log during its operation.
Upgrade to the latest 4.x series
After all deprecation warnings are resolved using version 3 of the Ruby gem, remove the version lock from the Gemfile and run bundle update appsignal again to update AppSignal for Ruby to version 4.
# Gemfile gem "appsignal"
Changes
Below are all the notable changes between the latest Ruby gem version 3 and the new version 4. Please go through them and update your application as described.
Main library
- The
Appsignal.start_loggermethod is removed. The logger is now automatically started onAppsignal.start. Applications need to remove theAppsignal.start_loggercall. - The AppSignal Ruby gem configuration is frozen after
Appsignal.startis called. The configuration can no longer be modified after the Ruby gem has started. - The
Appsignal.startmethod can only be called once. Subsequent calls are ignored by the Ruby gem.
Configuration
- AppSignal will not start if loading the
config/appsignal.ymlfile causes an error. Check the application output or theappsignal.logfile for any warnings. - Configure AppSignal in Ruby with the new
Appsignal.configurehelper. Apps using theAppsignal.config = Appsignal::Config.new(...)pattern must update their apps to use this method instead. - The
Appsignal.config =method is removed. Instead, use theAppsignal.configurehelper to configure AppSignal in Ruby. - The
skip_session_dataoption is removed. Use thesend_session_dataoption instead. - The
debugoption is removed. Use thelog_level: debugoption instead. - The
transaction_debug_modeoption is removed. Use thelog_level: traceoption instead. - The
working_dir_pathoption is removed. Use theworking_directory_pathoption instead.
Integrations
- The
Appsignal::Rack::EventHandlermiddleware is added. It will add theresponse_statustag to samples and track aresponse_statusmetric with the request's response status code. See our Rack integration docs for more information. - The
Appsignal::Rack::InstrumentationMiddlewaremiddleware replaces theAppsignal::Rack::GenericInstrumentationmiddleware. This new middleware does not set the action to "unknown" by default. It is required to set the action name in each app endpoint withAppsignal.set_actionwhen only using theInstrumentationMiddlewaremiddleware. See our Rack integration docs for more information. Appsignal::Grape::Middlewareis renamed toAppsignal::Rack::GrapeMiddleware.- The
Appsignal::Rack::StreamingListeneris replaced byAppsignal::Rack::InstrumentationMiddleware. - The
Appsignal::Hooks::SidekiqPluginis removed without replacement. - The Grape, Hanami, Padrino and Sinatra integrations now use the
Appsignal.loadmechanism to integrate with these libraries. Please follow the installation guides for these libraries to update to the new loading mechanism.- Sinatra
- Hanami
- Grape
- Padrino
- Using more than one of these libraries or mounting them on a Rails app? Follow this guide as well.
- The errors and performance issues reported by our Rake integration are now reported under the "rake" namespace.
Custom instrumentation
-
The
Appsignal.report_errorhelper makes it easier to always report errors, without knowing the difference between theAppsignal.set_errorandAppsignal.send_errorhelpers.Ruby# Before Appsignal.set_error(error) Appsignal.send_error(error, :tag => "value", "custom namespace") # After Appsignal.report_error(error) Appsignal.report_error(error) do Appsignal.set_namespace("custom namespace") Appsignal.add_tags(:tag => "value") end -
Multiple errors can be reported on one transaction with the
Appsignal.report_errorhelper. -
The
Appsignal.monitor_transactionandAppsignal.monitor_single_transactionhelpers are replaced by theAppsignal.monitorandAppsignal.monitor_and_stophelpers.- Note: newer versions of the Ruby gem have deprecated the
Appsignal.monitor_and_stophelper.
- Note: newer versions of the Ruby gem have deprecated the
-
New helpers for adding tags and sample data (parameters, request headers, session data and custom data) to transactions. See the customization helpers documentation for more information.
Ruby# Before Appsignal.tag_request(:tag => "value") Appsignal::Transaction.current.set_sample_data( "custom_data", :i18n => { :locale => "en_GB", :default_locale => "en_US" } ) # After Appsignal.add_tags(:tag => "value") Appsignal.add_custom_data( :i18n => { :locale => "en_GB", :default_locale => "en_US" } ) -
Sample data is amended by default. Adding additional parameters, request headers, session data and custom data will merge it with the previously set values. See the customization helpers documentation for more information.
-
The
Appsignal::Transaction::GenericRequesthelper is removed. Use our customization helpers to add metadata to the transaction. -
The
appsignal.actionandappsignal.routerequest environment keys are removed. Use theAppsignal.set_actionhelper to set the action name instead. -
The
tagsandnamespacearguments were removed from theAppsignal.set_errorandAppsignal.send_errorhelpers. Use the block method to customize the transaction before it's sent instead. See our exception handling guide for more information. -
The
Appsignal::Minutelyconstant is renamed toAppsignal::Probes. -
The
Appsignal::Probes.probes.registermethod is replaced withAppsignal::Probes.register. See our minutely probes documentation for more information. -
The
Appsignal.set_host_gaugeandAppsignal.set_process_gaugehelpers are removed without replacement. Instead, tag the metric with the hostname or process ID using theAppsignal.set_gaugehelper. -
The
Appsignal.listen_for_errorhelper is removed without replacement. Instead, manually rescue errors usingrescue => errorand report them using theAppsignal.report_errorhelper.
Library internals
Listed here are changes to library internals that may have previously been used in our documentation or support cases. We recommend you refrain from relying on these anymore. These are private components and may change at any moment. Breaking changes include:
- The
Appsignal::Transaction.createandAppsignal::Transaction.newmethods no longer accept theid,request, andoptionsarguments. The transaction ID is now automatically generated.- Instead of manually creating a Transaction object, use the
Appsignal.monitorhelper instead. - To set metadata on the transaction, use our customization helpers.
- Instead of manually creating a Transaction object, use the
- The
Appsignal::Transaction#set_http_or_background_actionmethod is removed. Use theAppsignal.set_actionhelper instead. - The
Appsignal::Transaction#set_http_or_background_queue_startmethod is removed. Use theAppsignal::Transaction#set_queue_starthelper instead. - The
AppSignal::Transaction#params=helper is removed. Use theAppsignal.add_paramshelper instead.
Welcome to 4.x!
This guide should cover upgrading most Ruby applications to AppSignal Ruby gem 4.x. If you have any questions, ran into errors, or would like assistance upgrading to the new version, please don't hesitate to contact support.