Class: Readme::Metrics
- Inherits:
-
Object
- Object
- Readme::Metrics
- Defined in:
- lib/readme/metrics.rb,
lib/readme/metrics/version.rb
Constant Summary collapse
- SDK_NAME =
'readme-metrics'- DEFAULT_BUFFER_LENGTH =
1- ENDPOINT =
URI.join(ENV['README_METRICS_SERVER'] || 'https://metrics.readme.io', '/v1/request')
- VERSION =
'2.4.1'
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options, &get_user_info) ⇒ Metrics
constructor
A new instance of Metrics.
Constructor Details
#initialize(app, options, &get_user_info) ⇒ Metrics
Returns a new instance of Metrics.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/readme/metrics.rb', line 24 def initialize(app, , &get_user_info) () raise Errors::ConfigurationError, Errors::MISSING_BLOCK_ERROR if get_user_info.nil? @app = app @development = [:development] || false @filter = Filter.for( reject: [:reject_params], allow_only: [:allow_only] ) @get_user_info = get_user_info buffer_length = [:buffer_length] || DEFAULT_BUFFER_LENGTH @@request_queue = [:request_queue] || Readme::RequestQueue.new([:api_key], buffer_length) @@logger = [:logger] || Logger.new($stdout) end |
Class Method Details
.logger ⇒ Object
20 21 22 |
# File 'lib/readme/metrics.rb', line 20 def self.logger @@logger end |
Instance Method Details
#call(env) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/readme/metrics.rb', line 41 def call(env) start_time = Time.now status, headers, body = @app.call(env) end_time = Time.now begin response = HttpResponse.from_parts(status, headers, body) process_response( response: response, env: env, start_time: start_time, end_time: end_time ) rescue => e Readme::Metrics.logger.warn "The following error occured when trying to log to the ReadMe metrics API: #{e.message}. Request not logged." [status, headers, body] end [status, headers, body] end |