Class: Yandex360::Instrumentation::Logging

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/yandex360/instrumentation.rb

Overview

Logging is per client rather than a global subscriber, so two clients with different loggers do not end up writing into each other's.

The token travels in a header and is never part of what is logged here.

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ Logging

Returns a new instance of Logging.



92
93
94
95
# File 'lib/yandex360/instrumentation.rb', line 92

def initialize(app, logger)
  super(app)
  @logger = logger
end

Instance Method Details

#call(env) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/yandex360/instrumentation.rb', line 97

def call(env)
  started = now
  method = env.method.to_s.upcase
  path = env.url.path

  @app.call(env).on_complete do |response_env|
    @logger.info { "[yandex360] #{method} #{path} #{response_env.status} #{ms_since(started)}ms" }
  end
rescue StandardError => e
  @logger.error { "[yandex360] #{method} #{path} raised #{e.class} after #{ms_since(started)}ms" }
  raise
end