Class: ZipkinTracer::Application
- Inherits:
-
Object
- Object
- ZipkinTracer::Application
- Defined in:
- lib/zipkin-tracer/application.rb
Overview
Useful methods on the Application we are instrumenting
Class Method Summary collapse
- .config(app) ⇒ Object
- .logger ⇒ Object
-
.routable_request?(env) ⇒ Boolean
Determines if our framework knows whether the request will be routed to a controller.
- .route(env) ⇒ Object
- .stub_env(env) ⇒ Object
Class Method Details
.config(app) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/zipkin-tracer/application.rb', line 41 def self.config(app) if app.respond_to?(:config) && app.config.respond_to?(:zipkin_tracer) app.config.zipkin_tracer else {} end end |
.logger ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/zipkin-tracer/application.rb', line 33 def self.logger if defined?(Rails.logger) Rails.logger else Logger.new(STDOUT) end end |
.routable_request?(env) ⇒ Boolean
Determines if our framework knows whether the request will be routed to a controller
5 6 7 8 9 10 11 12 13 |
# File 'lib/zipkin-tracer/application.rb', line 5 def self.routable_request?(env) return true unless defined?(Rails) # If not running on a Rails app, we can't verify if it is invalid path_info = env[ZipkinTracer::RackHandler::PATH_INFO] || "" http_method = env[ZipkinTracer::RackHandler::REQUEST_METHOD] Rails.application.routes.recognize_path(path_info, method: http_method) true rescue ActionController::RoutingError false end |
.route(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/zipkin-tracer/application.rb', line 22 def self.route(env) return nil unless defined?(Rails) req = Rack::Request.new(stub_env(env)) # Returns a string like /some/path/:id Rails.application.routes.router.recognize(req) do |route| return route.path.spec.to_s end rescue nil end |
.stub_env(env) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/zipkin-tracer/application.rb', line 15 def self.stub_env(env) { "PATH_INFO" => env[ZipkinTracer::RackHandler::PATH_INFO].dup, "REQUEST_METHOD" => env[ZipkinTracer::RackHandler::REQUEST_METHOD].dup } end |