This Rails Engine adds JavaScript that allows for the collection of users' browser timing information.
Once installed (see below), timing information will be submitted from browsers via AJAX, back to the mounted engine, and passed to any configured recorders.
Recorders can be any callable object, and can be configured like so:
NdrBrowserTimings.recorders << ->(timing) { MyService.notify(timing) }This gem bundles some recorders:
# Send info to the Rails log:
require 'ndr_browser_timings/recorders/logger'
NdrBrowserTimings.recorders << NdrBrowserTimings::Recorders::Logger.new
# Send info to prometheus:
require 'ndr_browser_timings/recorders/ndr_stats'
NdrStats.configure(...)
NdrBrowserTimings.recorders << NdrBrowserTimings::Recorders::NdrStats.newAdd this line to your application's Gemfile:
gem 'ndr_browser_timings'And then execute:
$ bundleOr install it yourself as:
$ gem install ndr_browser_timingsInject the client library into pages you want timings submitted from:
//=require 'ndr_browser_timings/ndr_browser_timings'and the <meta> tag to provide configuration to the client library:
<%= ndr_browser_timings_meta_tag %>By default, all requests will be instrumented. You can alternatively elect to only sample a fraction of requests, to reduce data collected:
<%= ndr_browser_timings_meta_tag(sample_rate: 0.1) %>This is an isolated engine, so you'll need to configure with an authentication check:
# Allow all requests through (careful!):
NdrBrowserTimings.check_current_user_authentication = ->(request) { true }The gem is available as open source under the terms of the MIT License.
Everyone interacting in the NdrBrowserTimings project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the CODE_OF_CONDUCT.md.
- javascript fallback