framed_rails
framed_rails is a gem to add Framed instrumentation to your rails4
app. For each pageview, it sends an event to Framed.
To use this with rails:
- Add
framed_railsto your Gemfile. - Add the following to
config/initializers/framed_rails.rb:
require 'framed_rails'
Framed.configure do |config|
config[:api_key] = 'YOUR_FRAMED_API_KEY'
end
Note that the threaded emitter works on a background thread. It is possible that events will be unreported when your containing process ends, unless you drain at process shutdown, i.e.
Framed.drain
If reporting fails, the exception will be logged to STDERR by default,
unless Rails is detected. In that case, the Rails.logger will be
used.
Configuration
| Key | Description | Default |
|---|---|---|
| :consumer | The emitter to be used for reporting. See the Emitters section below. | Framed::Emitters::Blocking |
| :endpoint | The URL to POST to, using basic auth with your write key | Framed::SEGMENT_API |
| :user_id_controller_method | The name of a controller method which returns the user ID, if any | 'framed_devise_user_id' |
| :logger | A Logger for reporting errors. | STDERR, or Rails.logger if detected. |
| :anonymous_cookie | The name of the in signed cookie for anonymous user IDs. Long-lived anonymous user IDs are issued anonymous users. | Framed::COOKIE_NAME |
| :user_id_controller_method | The name of a controller method which can provide the current User ID. Devise just works. | 'framed_devise_user_id' |
Emitters
By default, the report is sent with a blocking Emitter. If you would prefer a non-blocking emitter, you can include the following line in your configure block:
config[:consumer] => Framed::Emitters::Threaded
If you'd like to implement your own, see lib/framed/emitters.rb,
particularly Base and Blocking as examples.
Emitters included in this gem:
Framed::Emitters::InMemory- stores reported events in memory, rather than transmitting them. Events are later available as Framed.consumer.reported.Framed::Emitters::Logger- Logs an info message to config[:logger].Framed::Emitters::Blocking- Logs to Framed, using a blocking request.Framed::Emitters::Threaded- Logs to Framed, using a background-threaded request.