Save 37% off PRO during our Black Friday Sale! »

Rails Instrumentation

E0e036f89c14b3e59640318eedf9670b?s=47 Brooke Kuhlmann
December 30, 2020
76

Rails Instrumentation

Learn how to unleash the power of instrumentation already baked into your Rails application for monitoring, metrics, logging, and many other purposes. In this presentation, you'll learn how Rails uses the Observer Pattern to asynchronously instrument events for which you can subscribe to and even customize for your specific business needs.

E0e036f89c14b3e59640318eedf9670b?s=128

Brooke Kuhlmann

December 30, 2020
Tweet

Transcript

  1. Instrumentation Presented by Brooke Kuhlmann

  2. What?

  3. Active Support https://guides.rubyonrails.org/active_support_instrumentation.html

  4. Observer Pattern Instrumenter Subscriber

  5. Observer Pattern Instrumenter Subscriber Subscriber Subscriber Subscriber Subscriber

  6. Observer Pattern

  7. Observer Pattern Side Effects

  8. Observer Pattern

  9. Observer Pattern

  10. Implementation

  11. Implementation Instrumenter Subscriber

  12. Implementation Instrumenter Subscriber Specs

  13. Implementation Instrumenter Subscriber Specs Registration

  14. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter Format

  15. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "my.event.library", example: "data" Format

  16. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "my.event.library", example: "data" Event Name Format

  17. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "my.event.library", example: "data" Payload Format

  18. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter Example

  19. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "increment.metrics", key: "stripe.failure" Example

  20. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "increment.metrics", key: "stripe.failure" Event Example

  21. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "increment.metrics", key: "stripe.failure" Event Library Example

  22. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "increment.metrics", key: "stripe.failure" Event Library Payload Example

  23. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter Block

  24. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "duration.metrics", key: "stripe.transaction" do adapter.charge amount end

    Block
  25. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "duration.metrics", key: "stripe.transaction" do adapter.charge amount end

    Block
  26. https://guides.rubyonrails.org/active_support_instrumentation.html Instrumenter ActiveSupport::Notifications.instrument "duration.metrics", key: "stripe.transaction" do adapter.charge amount end

    Start Finish Block
  27. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  28. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  29. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  30. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  31. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  32. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  33. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  34. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  35. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  36. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  37. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  38. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber "stripe.success"

  39. https://guides.rubyonrails.org/active_support_instrumentation.html Subscriber

  40. Subscriber Specs

  41. Subscriber Specs

  42. Subscriber Specs

  43. Subscriber Specs

  44. Subscriber Specs

  45. Subscriber Specs

  46. Subscriber Specs

  47. Subscriber Specs

  48. Subscriber Specs

  49. Subscriber Specs Event

  50. Subscriber Specs Start

  51. Subscriber Specs Finish

  52. Subscriber Specs ID

  53. Subscriber Specs Payload

  54. Subscriber Specs

  55. Subscriber Specs

  56. Subscriber Specs

  57. Subscriber Specs

  58. Subscriber Specs

  59. Registration

  60. Registration config/initializers/subscribers.rb

  61. Registration config/initializers/subscribers.rb

  62. Registration config/initializers/subscribers.rb

  63. Registration config/initializers/subscribers.rb

  64. Registration

  65. Debugging https://github.com/amazing-print/amazing_print

  66. Debugging https://github.com/amazing-print/amazing_print bundle add amazing_print

  67. Debugging https://github.com/amazing-print/amazing_print bundle add amazing_print

  68. Debugging https://github.com/amazing-print/amazing_print bundle add amazing_print

  69. Debugging https://github.com/amazing-print/amazing_print bundle add amazing_print Regular Expression!

  70. Debugging https://github.com/amazing-print/amazing_print

  71. Debugging https://github.com/amazing-print/amazing_print

  72. Debugging https://github.com/amazing-print/amazing_print

  73. Asynchronous Messaging

  74. Asynchronous Messaging Instrumenter Subscriber Client Server

  75. Metrics Success Failure 0 4.5 9 13.5 18 Stripe

  76. Existing Instrumentation https://guides.rubyonrails.org/active_support_instrumentation.html

  77. Existing Instrumentation ~51 Instrumenters https://guides.rubyonrails.org/active_support_instrumentation.html

  78. Action Controller https://guides.rubyonrails.org/active_support_instrumentation.html

  79. Action Controller https://guides.rubyonrails.org/active_support_instrumentation.html process_action.action_controller

  80. Active Record https://guides.rubyonrails.org/active_support_instrumentation.html

  81. Active Record https://guides.rubyonrails.org/active_support_instrumentation.html sql.active_record

  82. Action Mailer https://guides.rubyonrails.org/active_support_instrumentation.html

  83. Action Mailer https://guides.rubyonrails.org/active_support_instrumentation.html deliver.action_mailer

  84. Active Job https://guides.rubyonrails.org/active_support_instrumentation.html

  85. Active Job https://guides.rubyonrails.org/active_support_instrumentation.html perform.active_job enqueue_retry.active_job discard.active_job

  86. Guidelines https://guides.rubyonrails.org/active_support_instrumentation.html

  87. Guidelines https://guides.rubyonrails.org/active_support_instrumentation.html • Use for light weight ancillary tasks only.

  88. Guidelines https://guides.rubyonrails.org/active_support_instrumentation.html • Use for light weight ancillary tasks only.

    • Use for logging, metrics, etc.
  89. Guidelines https://guides.rubyonrails.org/active_support_instrumentation.html • Use for light weight ancillary tasks only.

    • Use for logging, metrics, etc. • Keep subscribers small and simple.
  90. Thanks https://www.alchemists.io