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. Effective Rails
    Instrumentation

    View full-size slide

  2. André Luís Anastácio
    Desenvolvedor
    Twitter / Github - ndrluis

    View full-size slide

  3. Belo Horizonte

    View full-size slide

  4. Use New Relic, Papertrail e Rollbar.

    View full-size slide

  5. Use New Relic, Papertrail e Rollbar.
    Duvidas?

    View full-size slide

  6. Testar não é negociável

    View full-size slide

  7. Mensurar/Instrumentar
    não deveria ser negociável

    View full-size slide

  8. Exemplo
    E-commerce

    View full-size slide

  9. 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

    View full-size slide

  10. ActiveSupport::TaggedLogging

    View full-size slide

  11. 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

    View full-size slide

  12. Serviço de Terceiros
    Rollbar

    View full-size slide

  13. 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

    View full-size slide

  14. Como escolher entre
    TaggedLogging
    e
    Rollbar?

    View full-size slide

  15. Facilitar a
    reprodução do Erro

    View full-size slide

  16. BONUS STAGE
    Performance

    View full-size slide