Trace events happened while running rails server. It will listen and record events data for every single route (from REQUEST to RESPONSE). Currently, the events included are :call
and :line
.
-
Checkout to a new branch
git checkout -b try/trace-rails
-
Copy this folder into
./lib
folder. It should be something like this:root ├── app └── lib └── trace_rails ├── README.md # You're now reading this ├── data ├── tracer.rb ├── tracer_middleware.rb └── tracer_logger.rb
-
Add
config.middleware.use TracerMiddleware
intoconfig/application.rb
. However this will result error due to middleware not found. To fix this, just importrequire_relative '../lib/trace_rails/tracer_middleware'
at the top ofconfig/application.rb
. -
Install the following gems locally (not in Gemfile)
- Rainbow, a ruby gem for colorizing printed text on ANSI terminals.
Run
gem install rainbow
- (OPTIONAL) method_source, to retrieve the sourcecode for a method.
Run
gem install method_source
- Rainbow, a ruby gem for colorizing printed text on ANSI terminals.
Run
-
After finished #Setup, start the server using
rails server
. Reminder note: if you have any other background job, you need to run it on other terminal, it doesn't work well willforeman start -f Procfile.dev
-
Then visit any page you like.
-
You can view the result in 2 places:
- Terminal. The terminal will give you an overall report of what methods being called.
/data/
. JSON data stored here represents sequencial data of what methods being called. It will store the previous 5 or 3 routes ran in your server. (configurable atTracerCollector::CALLS_LIMIT
orTracerCollector::LINES_LIMIT
)/data/calls.json
stores method called data./data/lines.json
stores line executed data.
Reminder: Middlewares are loaded once and are not monitored for changes. You will have to restart the server for changes to be reflected in the running application. See rails documentation for more details.
-
@opts
insidetracer_middlware.rb
is configuration options for event type tracing and data format. -
CALLS_LIMIT
,LINES_LIMIT
, andCALLER_LIMIT
insideTracerCollector
set the limit for data stored indata/
.
Apologize that many of the details are not documented clearly. This is just a side project used to learn middlware, and design patterns like collector and singleton. However, please feel very free to ping me if you have any question and wanna provide any suggestion. Thanks :)