Skip to content

NHSDigital/ndr_browser_timings

Repository files navigation

NdrBrowserTimings Build Status Gem Version

This Rails Engine adds JavaScript that allows for the collection of users' browser timing information.

Usage

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.new

Installation

Add this line to your application's Gemfile:

gem 'ndr_browser_timings'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ndr_browser_timings

Inject 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 }

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the NdrBrowserTimings project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the CODE_OF_CONDUCT.md.

TODO:

  • javascript fallback

About

Rails engine to performs client-side instrumentation and feeds back to the application.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors