Before you begin
- Ruby 3.0 or later.
-
An Observe key that starts with
obs_. Read Get an ingest key. - Version 0.2.0 of the gem. It has no runtime dependencies.
Install
# Gemfile
gem "postdeploy", "~> 0.2"
Run bundle install, then set POSTDEPLOY_API_KEY in the environment of every process that reports errors.
Rails
The gem's Railtie adds PostDeploy::RackMiddleware inside ActionDispatch::DebugExceptions and reports errors from Rails.error. It also hooks into ActiveJob and Sidekiq when they are present. Do not add the middleware again.
class ApplicationController < ActionController::Base
before_action do
PostDeploy.set_user(id: current_user.id, email: current_user.email) if current_user
end
end
Rack
Add the middleware first. It reports the error with the request method, URL without query string, parameters and allow-listed headers, then raises the error again so your error page still renders.
require "postdeploy"
use PostDeploy::RackMiddleware
run lambda { |env|
PostDeploy.set_user(id: "user_rack_1")
raise "Checkout failed" if env["PATH_INFO"] == "/boom"
[200, { "content-type" => "text/plain" }, ["ok"]]
}
Scripts and tasks
Call PostDeploy.flush before a short process exits. Version 0.2.0 does not flush at exit, so a script that ends without it loses its events.
require "postdeploy"
PostDeploy.configure do |config|
config.environment = "production"
config.release = ENV["GIT_SHA"]
end
PostDeploy.set_user(id: "user_456", email: "[email protected]")
PostDeploy.set_tag("plan", "team")
PostDeploy.set_context("order", { order_id: "ord_789" })
begin
raise ArgumentError, "Invoice total is negative"
rescue => e
PostDeploy.capture_exception(e, context: { feature: "billing" })
end
PostDeploy.capture_message("Low disk space", level: "warning")
PostDeploy.flush
Verify
-
Step 1. Run the script.
Terminal shellPOSTDEPLOY_API_KEY=obs_your_key ruby report.rb -
Step 2. Open Observe. The table shows "ArgumentError: Invoice total is negative" as an error and "Low disk space" as a warning.
Troubleshoot
- A rake task or script reports nothing
-
Call
PostDeploy.flushbefore the process exits. - Errors in development never arrive
-
Keep the Railtie's position. A second middleware at the top of the stack runs after
DebugExceptionshas handled the error. - Events go to the wrong host
-
Leave
config.endpointandPOSTDEPLOY_INGEST_URLunset in production. The default is the PostDeploy ingest host. - The error page still renders
- The middleware raises the error again after it reports it. This is expected.
Limits
- Version 0.2.0 does not flush at process exit.
-
The gem README in 0.2.0 describes an older key format. Keys start with
obs_.