Class: Whatsapp::Instrumentation
- Inherits:
-
Object
- Object
- Whatsapp::Instrumentation
- Defined in:
- lib/ruby/whatsapp/instrumentation.rb
Overview
Instrumentation for logging HTTP requests and responses.
Instance Method Summary collapse
- #finish(_, payload) ⇒ Object
-
#initialize(logger) ⇒ Instrumentation
constructor
A new instance of Instrumentation.
- #instrument(name, payload = {}) ⇒ Object
- #start(_, payload) ⇒ Object
Constructor Details
#initialize(logger) ⇒ Instrumentation
Returns a new instance of Instrumentation.
7 8 9 |
# File 'lib/ruby/whatsapp/instrumentation.rb', line 7 def initialize(logger) @logger = logger end |
Instance Method Details
#finish(_, payload) ⇒ Object
29 30 31 32 |
# File 'lib/ruby/whatsapp/instrumentation.rb', line 29 def finish(_, payload) response = payload[:response] @logger.info("#{response.status.code} #{response.status.reason}") end |
#instrument(name, payload = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/ruby/whatsapp/instrumentation.rb', line 13 def instrument(name, payload = {}) error = payload[:error] return unless error @logger.error("#{name}: #{error.}") end |
#start(_, payload) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ruby/whatsapp/instrumentation.rb', line 21 def start(_, payload) request = payload[:request] uri = request.uri # Log without the query string so identifiers/secrets in params are not logged. @logger.info("#{request.verb.to_s.upcase} #{uri.scheme}://#{uri.host}#{uri.path}") end |