Using highlight.io with Ruby on Rails
Learn how to set up highlight.io on your Rails backend.
Add `tracingOrigins` to your client Highlight snippet.
This backend SDK requires one of the Highlight frontend SDKs to be installed, so please make sure you've followed the fullstack mapping guide first.
H.init("<YOUR_PROJECT_ID>", {
tracingOrigins: ['localhost', 'example.myapp.com/backend'],
networkRecording: {
enabled: true,
recordHeadersAndBody: true,
},
});
Install the Highlight Ruby SDK.
Add Highlight to your Gemfile and install with Bundler.
gem "highlight_io"
bundle install
Initialize the Highlight Ruby SDK.
Highlight.init
initializes the SDK. Setting your project ID also lets Highlight record errors for background tasks and processes that aren't associated with a frontend session.
require "highlight"
Highlight.init("<YOUR_PROJECT_ID>", environment: "production") do |c|
c.service_name = "my-app"
c.service_version = "1.0.0"
end
Verify your errors are being recorded.
Now that you've set up the Middleware, you can verify that the backend error handling works by throwing an error in a controller. Visit the highlight errors page and check that backend errors are coming in.
class ArticlesController < ApplicationController
def index
1/0
end
end
Record custom errors. (optional)
If you want to explicitly send an error to Highlight, you can use the error
method within traced code.
Highlight.exception(e)
Set up logging.
Start sending logs to Highlight! Follow the logging setup guide to get started.