Using highlight.io with Other Ruby Frameworks
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,
},
});
Add Highlight to your Gemfile and install with Bundler.
gem "highlight_io"
bundle install
Highlight::H.new
initializes the SDK and allows you to call the singleton Highlight::H.instance
. 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::H.new("<YOUR_PROJECT_ID>", environment: "production") do |c|
c.service_name = "my-app"
c.service_version = "1.0.0"
end
trace
will automatically record raised exceptions and send them to Highlight.
require "highlight"
Highlight::H.instance.trace(nil, nil) do
# your code here
end
Now that you've set up the Middleware, verify that the backend error handling works by consuming an error from traced code.
If you want to explicitly send an error to Highlight, you can use the record_exception
method within traced code.
Highlight::H.instance.record_exception(e)
Start sending logs to Highlight! Follow the logging setup guide to get started.