Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Effective Rails Instrumentation

Effective Rails Instrumentation

Andre Luis Anastacio

November 18, 2017
Tweet

More Decks by Andre Luis Anastacio

Other Decks in Technology

Transcript

  1. class PaymentService def initialize(order) @order = order end def pay

    response = ExternalPaymentStuff.pay(order) if response.success? @order.pay! else fail SomePaymentError, response.error_message end end end
  2. class PaymentService def initialize(order) @order = order end def pay

    logger.tagged(order_tag, client_tag) do response = ExternalPaymentStuff.pay(order) if response.success? order.pay! else logger.error(response.body) fail SomePaymentError, response.error_message end end end private attr_accessor :order def logger @logger ||= Rails.logger end def order_tag "ORDER ##{order.id}" end def client_tag "CLIENT ##{order.client_id}" end end
  3. class PaymentService def initialize(order) @order = order end def pay

    response = ExternalPaymentStuff.pay(order) if response.success? order.pay! else Rollbar.error('PaymentError', response_body: response.body, order_id: order.id) fail SomePaymentError, response.error_message end end private attr_accessor :order end