Gem
Install one adapter.
Ruby Core, Rack middleware and compatible Rails dependencies are resolved automatically.
bundle add apirelio-railsRailtie
Configure one initializer.
The Railtie inserts Apirelio into the Rails middleware stack automatically.
# config/initializers/apirelio.rb
Apirelio::Rails.configure do |config|
config.api_key = ENV.fetch("APIRELIO_API_KEY", "")
config.endpoint = ENV.fetch("APIRELIO_ENDPOINT", "https://apirelio.com")
config.service = "billing-api"
config.environment = Rails.env
config.release = ENV["APIRELIO_RELEASE"]
config.include_routes = ["/api/**"]
config.exclude_routes = ["/api/health", "/api/internal/**"]
config.metadata_keys = ["region"]
endB2B context
Resolve stable identities.
Run authentication before Apirelio completes the request, then expose the current account and API client through the Rack environment or another request-local source.
Apirelio::Rails.configure do |config|
# ...connection options...
config.customer_resolver = ->(env) do
account = env["current_account"]
account && {
id: account.id.to_s,
name: account.name,
plan: account.plan
}
end
config.application_resolver = ->(env) do
client = env["current_api_client"]
client && { id: client.id.to_s, name: client.name }
end
endSafe enrichment
Add bounded operational context.
Only scalar keys included in metadata_keys are retained. Prefer stable error codes over exception messages.
class Api::InvoicesController < ApplicationController
def create
Apirelio::Rails.context(request.env)
&.add_metadata(region: "eu-central")
&.set_error_code("PAYMENT_REQUIRED")
head :accepted
end
endLifecycle
Resolved, asynchronous and fail-safe.
The integration records the final status, duration, matched Rails route and controller action. Events enter a bounded background queue; resolver and delivery failures never replace the original response or exception.
Request and response bodies, query strings, credentials, cookies and client IP addresses are never included.