Star us on GitHub
Star
Menu

Using highlight.io with Ruby on Rails

Learn how to set up highlight.io on your Rails backend.

1

Configure client-side Highlight. (optional)

If you're using Highlight on the frontend for your application, make sure you've initialized it correctly and followed the fullstack mapping guide.

2

Install the Highlight Ruby SDK.

Add Highlight to your Gemfile and install with Bundler.

gem "highlight_io" bundle install
Copy
3

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
Copy
4

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
Copy
5

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)
Copy
6

Set up the Highlight Logger.

In a Rails initializer, you can replace or extend your logger with the Highlight Logger.

require "highlight" Highlight.init("<YOUR_PROJECT_ID>", environment: "production") do |c| c.service_name = "my-rails-app" c.service_version = "git-sha" end # you can replace the Rails.logger with Highlight's Rails.logger = Highlight::Logger.new(STDOUT) # or broadcast logs to Highlight's logger highlight_logger = Highlight::Logger.new(nil) Rails.logger.broadcast_to(highlight_logger) # or if using an older version of Rails, you can extend the logger Rails.logger.extend(ActiveSupport::Logger.broadcast(highlight_logger))
Copy
7

Verify your errors are being recorded.

Now that you've set up the Middleware, verify that the backend error handling works by consuming an error from traced code.

8

Verify your backend logs are being recorded.

Visit the highlight logs portal and check that backend logs are coming in.

9

Record custom traces. (optional)

If you want to explicitly send a trace to Highlight, you can use the start_span method to wrap any code you want to trace.

Highlight.start_span('my-span') do |span| # ... end
Copy
10

Verify your backend traces are being recorded.

Visit the highlight traces portal and check that backend traces are coming in.