Integrating Telebugs with a Ruby on Rails application
Any Ruby on Rails application can be integrated with Telebugs using the telebugs-rails gem. In this guide, you will learn how to install and configure Telebugs in your Rails application.
For plain Ruby applications and scripts, please refer to the Ruby integration guide.
Installation
Add the telebugs-rails
gem to your Gemfile
:
bundle add telebugs-rails
Generate the initializer file:
bin/rails generate telebugs
This will create a new file at config/initializers/telebugs.rb
.
Telebugs.configure do |config|
config.api_key = ENV["TELEBUGS_API_KEY"] || Rails.application.credentials.telebugs_api_key
end
You can ask @TelebugsBot for your API key or find it in your project's dashboard.
Add your project's API key
By default, the API key is read from:
- the
TELEBUGS_API_KEY
environment variable -
telebugs_api_key
from credentials
You may choose to set the API key directly in the initializer file, but it is recommended to use environment variables or credentials for security reasons.
To add the API key to your credentials, run the following command:
bin/rails credentials:edit
Add the following line to your config/credentials.yml.enc
file:
telebugs_api_key: YOUR_API_KEY
Save the file and close the editor. The API key is now stored in your credentials.
Sending a test notification
You can send a test notification to your project by running the following command:
RAILS_ENV=production bin/rails r 'p Telebugs.report(StandardError.new("Hello, Telebugs!")).wait'
If everything is set up correctly, you should receive a test notification in your project.
Reporting errors
Reporting unhandled errors
Telebugs will automatically report unhandled errors in your Rails application.
Reporting handled errors
You can manually report errors by calling the Telebugs.report
method:
begin
# Your code here
rescue StandardError => e
Telebugs.report(e)
end
For more information on reporting errors, configuration details, and advanced usage, please refer to the Ruby integration guide.