Class: Appsignal::Rack::Utils
Class Method Summary collapse
-
.queue_start_from(env) ⇒ Integer, NilClass
Fetch the queue start time from the request environment.
-
.request_method_from(request) ⇒ String, NilClass
Fetch the HTTP request method from the request.
-
.request_value_from(request, name) ⇒ Object, NilClass
Fetch a value that describes the request, named after the method that reads it.
Class Method Details
.queue_start_from(env) ⇒ Integer, NilClass
Fetch the queue start time from the request environment.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/appsignal/rack.rb', line 55 def self.queue_start_from(env) return unless env env_var = env["HTTP_X_QUEUE_START"] || env["HTTP_X_REQUEST_START"] return unless env_var cleaned_value = env_var.tr("^0-9", "") return if cleaned_value.empty? value = cleaned_value.to_i if value > 4_102_441_200_000 # Value is in microseconds. Transform to milliseconds. value / 1_000 elsif value < 946_681_200_000 # Value is too low to be plausible nil else # Value is in milliseconds value end end |
.request_method_from(request) ⇒ String, NilClass
Fetch the HTTP request method from the request.
The request class is configurable, so reading the method can raise. Log and return nil in that case, leaving it to the caller to skip whatever it needed the method for.
22 23 24 25 26 27 28 29 |
# File 'lib/appsignal/rack.rb', line 22 def self.request_method_from(request) request.request_method rescue => error Appsignal.internal_logger.error( "Exception while fetching the HTTP request method: #{error.class}: #{error}" ) nil end |
.request_value_from(request, name) ⇒ Object, NilClass
Fetch a value that describes the request, named after the method that reads it.
The request class is configurable, so reading from the request can raise. Log and return nil in that case, leaving it to the caller to skip whatever it needed the value for.
41 42 43 44 45 46 47 48 |
# File 'lib/appsignal/rack.rb', line 41 def self.request_value_from(request, name) request.public_send(name) rescue => error Appsignal.internal_logger.error( "Exception while fetching the HTTP request #{name}: #{error.class}: #{error}" ) nil end |