Instrumenting Ruby on Rails With Traceview


Published on

Installation and setup of TraceView for your Ruby application is a simple two step process that can be done in 10 minutes or less. Traceview gives a unique in-depth view into requests even as they cross hosts and software stacks. I run it on Gameface and PasswordPusher - it’s an essential tool in identifying problem areas, application performance bottlenecks and simply poor performing code. (Read: ActionView) To learn more about TraceView, visit or read the AppNeta blog at

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Instrumenting Ruby on Rails With Traceview

  1. 1.    1  On  Building                :  Instrumen1ng  Ruby  with  TraceView  in  10  minutes      Peter  Lombardo  h$p://   h$p://  
  2. 2. I’ve  been  a  Rubyist  and  Linux  addict  for  over  a  decade,  mainly  developing  in  Ruby  and  JavaScript  (as  well  as  PHP  and  Perl).  I’m  the  creator  of  numerous  soHware  tools  and  applicaIons,  most  recently  Password  Pusher,  a  Ruby  on  Rails  applicaIon  to  communicate  passwords  over  the  web  and  Gameface,  a  social  networking  plaLorm  for  gamers  using  Rails  3.      When  I’m  not  creaIng  my  own  applicaIons,  I  help  develop  and  maintain  the  infrastructure  at  OurStage  and  manage  the  Ruby  community  for  AppNeta.  Peter  Lombardo  
  3. 3.  “Gameface  was  created  to    showcase  games,    the  people  who  play  them,  and  the  characters  they  play”    
  4. 4. TraceView  by  AppNeta  gives  a  unique  in-­‐depth  view  into  requests  even  as  they  cross  hosts  and  soKware  stacks.    Installa1on  and  setup  of  TraceView  for  your  app  is  a  simple  two  step  process  that  can  be  done  in  10  minutes  or  less.    h$p://   h$p://  
  5. 5. TraceView  provides  deep  performance  monitoring  of  web  apps.    It  gives  insight  into  your  web  app  performance  such  as  this:          
  6. 6. …and  a  per  request  drill-­‐down  that  shows  you  the  niOy  griOy  detail  of  where  1me  is  spent  in  individual  requests  
  7. 7. and  even  end-­‐user  monitoring:      
  8. 8. I  run  it  on  Gameface  and  PasswordPusher  -­‐  it’s  essen1al  in  iden1fying  problem  areas,  performance  boOlenecks  and  poor  performing  code.  (Read:  Ac1onView)        Disclaimer:  I  authored  the  Ruby  instrumenta6on  for  Traceview  so  I  may  be  a  bit  biased.  …but  with  good  reason!  h$p://   h$p://  
  9. 9. Installa1on    
  10. 10. Installing  TraceView  consists  of  two  parts:      1)  installing  the  system  daemon  on  your  host,  and    2)  installing  the  Ruby  gem  in  your  applica1on  h$p://­‐datasheet  
  11. 11. Why  a  system  daemon?      TraceView  uses  a  system  daemon  to  collect  instrumenta6on  from  sources  beyond  applica6on  code  such  as  host  metrics,  Apache  or  Resque.  
  12. 12. The  system  daemon  is  installed  with  two  commands  that  can  be  pasted  into  your  shell.      An  account  specific  version  of  these  commands  is  available  in  your  TraceView  dashboard  once  you  create  an  account.      (Under  SeWngs;  App  Configura1on;  Trace  New  Hosts)    
  13. 13. And  the  gem  for  your  applica1on  Gemfile  available  on  RubyGems:    h$ps://  gem oboe !
  14. 14. Setup    
  15. 15. TraceView  func1ons  by  sampling  a  subset  of  all  requests  that  go  through  your  web  applica1on.      This  sample  rate  must  be  set  at  the  entry  point  of  requests  in  your  applica1on.    
  16. 16. This  can  be  a  load  balancer,  Apache/nginx  or  Ruby  itself.      Successive  hosts  and  soKware  stacks  that  requests  pass  through  will  act  appropriately  according  to  upstream  seWngs.!
  17. 17. Yes.      That  means  requests  can  be  traced  across  hosts,  so6ware  stacks,  even  track  internal  API  calls  via  HTTP/SOAP/REST  which  make  for  spectacular  applicaEon  insight.    …But  that’s  another  post  for  another  Eme.    
  18. 18. For  this  walkthrough  we’re  going  to  assume  that  you’re  running  a  Ruby  on  Rails  applica1on  with  Unicorn,  Thin,  Puma  or  any  other  Rack  based  Ruby  webserver.    To  instead  configure  Apache/nginx  as  the  entry  point,  see  here.  
  19. 19. This  can  be  a  load  balancer,  Apache/nginx  or  Ruby  itself.      Successive  hosts  and  soKware  stacks  that  requests  pass  through  will  act  appropriately  according  to  upstream  seWngs.!
  20. 20. If  you  setup  Apache  or  nginx  as  your  entry  point  then  you  can  skip  this  part  enErely.    The                      gem  will  take  it’s  tracing  instrucEons  from  upstream  automaEcally.  Oboe!
  21. 21. When  the                    gem  is  installed  in  your  applica1on,  it  makes  available    !!which  is  a  nested  hash  of  configura1on  op1ons  that  affect  how  your  applica1on  is  instrumented.  Oboe::Config !Oboe!
  22. 22. Luckily,  the  defaults  are  very  smart  and  only  a  couple  ini1al  values  need  to  be  configured.    The  two  required  values  are:    Oboe::Config[:tracing_mode] = always !Oboe::config[:sample_rate] = 100000 # 10% of incoming requests !
  23. 23. These  values  enable  tracing  (:tracing_mode)  and  sets  the  sample  rate  to  10%  (:sample_rate).    The  sample_rate  is  calculated  by  the  value  out  of  one  million.      e.g.  300000  would  equal  a  30%  sample  rate  meaning  3  out  of  10  requests  would  be  sampled.      (For  low  traffic  sites,  you  may  want  to  set  these  values  higher.)!
  24. 24. These  values  are  usually  set  in  a  Rails  ini1alizer  for  Ruby  on  Rails.      See  the  OpEonal  Rails  IniEalizer  sec1on  on  this  page.      A  complete  list  of  all  configura1on  op1ons  for   is  here.!Oboe::Config !
  25. 25. And  that’s  it.  Now  to  the  good  stuff…!
  26. 26. GeWng  Performance  Data    
  27. 27. If  you  want  to  test  that  the  oboe  gem  is  func1onal,  start-­‐up  a  Rails  console,  you  should  see  a  message  to  stdout  similar  to:     Tracelytics oboe gem successfully loaded. !
  28. 28. Note  that  on  hosts  that  don’t  have  the  system  daemon  installed,  the  oboe  gem  disables  itself  and  outputs  a  message  to  that  fact:        Deploy/restart  your  applica1on  and  you  should  start  seeing  traces  show  up  in  your  TraceView  dashboard  aKer  a  couple  minutes.  Unsupported Tracelytics environment (no libs). Going No-op. !
  29. 29. Things  are  moving  fast  for  the  Ruby  language  instrumenta1on  in  TraceView.      We  support  tracing  of:          
  30. 30. memcache-­‐client,  memcached,    dalli,  mongo,    moped,  mongoid,  mongomapper,  cassandra,    Ac1veRecord  (postgres,  mysql,  mysql2)        …plus  more.    
  31. 31. Most  recently  we  added  support  for  Rack  and  Resque  tracing.    For  a  full-­‐list  of  supported  libraries,  see  this  ar1cle.!
  32. 32. Extras:    Some  Random  Chart  Porn    
  33. 33. A  screenshot  that  I  sent  to  Linode  when  performance  unexpectedly  dropped:    
  34. 34. Linode  migrated  my  VPS  to  a  lesser  u1lized  host  with  evident  results    (Thanks  Linode):    
  35. 35. An  older  issue  that  Gameface  had  with  atrocious  rendering  1mes:    
  36. 36. If  you  haven’t  tried  out  TraceView  yet,  give  it  a  run.      You  won’t  be  disappointed.      Note:  AppNeta  now  offers  free  tracing  for  single  projects.  Check  it  out  on  their  pricing  page.