Dristi Client
Ruby client for Dristi error tracking service.
Requirements
- Ruby >= 3.0.0
- Rails (optional, for automatic middleware integration)
Installation
Add this line to your application's Gemfile:
gem "dristi-client"Then execute:
bundle installConfiguration
Create an initializer at config/initializers/dristi_client.rb:
DristiClient.configure do |config|
config.api_token = ENV["DRISTI_API_TOKEN"]
# Optional: disable in specific environments
config.enabled = !Rails.env.test?
# Optional: ignore specific exception classes
config.ignored_exceptions = [ActiveRecord::RecordNotFound]
endConfiguration Options
| Option | Type | Default | Description |
|---|---|---|---|
api_token |
String | nil |
Required. API token for authentication |
enabled |
Boolean | true |
Enable/disable error reporting |
ignored_exceptions |
Array | [] |
Exception classes to skip |
Usage
Automatic Error Capture
The gem automatically captures unhandled exceptions via Rack middleware. No additional code is needed for Rails applications.
The middleware captures the following context automatically:
-
request_method- HTTP method (GET, POST, etc.) -
request_path- Request path -
request_params- Request parameters (sensitive params filtered) -
query_string- Query string -
user_agent- Browser/client user agent -
remote_ip- Client IP address -
request_id- Rails request ID -
referer- HTTP referer URL (if present) -
referer_path- Path portion of the referer URL
Manual Error Reporting
You can manually report errors with additional context:
begin
# risky code
rescue => e
DristiClient.capture(e, {
user_id: current_user.id,
action: "checkout",
custom_data: { cart_items: cart.items.count }
})
raise
endCustom Context
Add any relevant context to help with debugging:
DristiClient.capture(exception, {
user_id: current_user&.id,
user_email: current_user&.email,
feature_flags: FeatureFlags.active,
request_id: request.request_id
})Error Payload
Errors are reported with the following structure:
{
"exception_class": "NoMethodError",
"message": "undefined method 'foo' for nil:NilClass",
"backtrace": ["app/models/user.rb:42:in `process'", "..."],
"context": { "user_id": 123 },
"environment": {
"ruby_version": "3.3.0",
"rails_version": "8.1.2",
"rails_env": "production",
"hostname": "web-1"
},
"occurred_at": "2025-01-21T12:00:00Z"
}Retry & Fallback Behavior
- Errors are sent in a background thread to avoid blocking requests
- Failed requests retry up to 3 times with exponential backoff (1s, 2s, 4s)
- If all retries fail, errors are written to
tmp/dristi_fallback.jsonl
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/logicalgroove/dristi-client.
License
MIT License. See LICENSE.txt.