Skip to content

Moesif/moesif-rails4-example

Repository files navigation

Moesif Rails 4 Example with Rails

Ruby Rack is what most Ruby Web frameworks like Rails are built on top of. Rails is one of the most popular frameworks.

Moesif is an API analytics and monitoring platform. moesif-rack is a middleware that makes integration with Moesif easy for Rack based applications and frameworks, including Rails.

This example is a Rails web application with Moesif Rack integrated. Its based on the quick start tutorials of Rails and this popular blog post regarding RESTful APIs on Rails

Key changes

moesif-rack's documentation has detailed installation instructions and configuration options. Key changes to the base example to enable Moesif:

  • Add gem 'moesif_rack' to the Gemfile
  • Modify the config/application.rb to use your Moesif Application Id.

Your Moesif Application Id can be found in the Moesif Portal. After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps.

You can always find your Moesif Application Id at any time by logging into the Moesif Portal, click on the top right menu, and then clicking Installation.

How to run

  1. Verify Ruby and Rails versions is 2.3 and above via ruby -v Verify Rails is 4.0 or higher via rails --version

  2. Install all dependencies via bundle install

  3. Be sure to edit the config/application.rb to change the application id to your real one obtained from Moesif.

# config/application.rb
moesif_options = {
  'application_id' => 'Your application Id'
}
  1. To run
bin/rails server

You may have to run bin/rake db:migrate RAILS_ENV=development first to set up db.

  1. To see a list of routes that you can run tests against run rake routes. Send some requests to the API routes and verify that the API calls are captured in your Moesif account.