Class: OneApm::Rack::MiddlewareWrapper
- Inherits:
-
Object
- Object
- OneApm::Rack::MiddlewareWrapper
- Includes:
- MiddlewareTracing
- Defined in:
- lib/one_apm/rack/middleware_wrapper.rb
Defined Under Namespace
Classes: MiddlewareClassWrapper
Constant Summary
Constants included from MiddlewareTracing
OneApm::Rack::MiddlewareTracing::OA_TXN_STARTED_KEY
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#transaction_options ⇒ Object
readonly
Returns the value of attribute transaction_options.
Class Method Summary collapse
- .is_sinatra_app?(target) ⇒ Boolean
- .needs_wrapping?(target) ⇒ Boolean
- .wrap(target, is_app = false) ⇒ Object
- .wrap_class(target_class) ⇒ Object
Instance Method Summary collapse
- #determine_category ⇒ Object
-
#determine_class_name ⇒ Object
In ‘normal’ usage, the target will be an application instance that responds to #call.
- #determine_prefix ⇒ Object
-
#initialize(target, is_app = false) ⇒ MiddlewareWrapper
constructor
A new instance of MiddlewareWrapper.
- #middleware_ignore? ⇒ Boolean
Methods included from MiddlewareTracing
#_oa_has_middleware_tracing, #build_transaction_options, #call, #capture_http_response_code, #events, #merge_first_middleware_options, #note_transaction_started
Constructor Details
#initialize(target, is_app = false) ⇒ MiddlewareWrapper
Returns a new instance of MiddlewareWrapper.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 55 def initialize(target, is_app = false) @target = target @is_app = is_app @category = determine_category @target_class_name = determine_class_name @transaction_name = "#{determine_prefix}#{@target_class_name}/call" @transaction_options = { :transaction_name => @transaction_name } end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
53 54 55 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 53 def category @category end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
53 54 55 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 53 def target @target end |
#transaction_options ⇒ Object (readonly)
Returns the value of attribute transaction_options.
53 54 55 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 53 def @transaction_options end |
Class Method Details
.is_sinatra_app?(target) ⇒ Boolean
30 31 32 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 30 def is_sinatra_app?(target) defined?(::Sinatra::Base) && target.kind_of?(::Sinatra::Base) end |
.needs_wrapping?(target) ⇒ Boolean
38 39 40 41 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 38 def needs_wrapping?(target) !target.respond_to?(:_oa_has_middleware_tracing) && !is_sinatra_app?(target) end |
.wrap(target, is_app = false) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 43 def wrap(target, is_app = false) if needs_wrapping?(target) self.new(target, is_app) else target end end |
.wrap_class(target_class) ⇒ Object
34 35 36 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 34 def wrap_class(target_class) MiddlewareClassWrapper.new(target_class) end |
Instance Method Details
#determine_category ⇒ Object
66 67 68 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 66 def determine_category @is_app ? :rack : :middleware end |
#determine_class_name ⇒ Object
In ‘normal’ usage, the target will be an application instance that responds to #call. With Rails, however, the target may be a subclass of Rails::Application that defines a method_missing that proxies #call to a singleton instance of the the subclass. We need to ensure that we capture the correct name in both cases.
83 84 85 86 87 88 89 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 83 def determine_class_name if @target.is_a?(Class) @target.name else @target.class.name end end |
#determine_prefix ⇒ Object
70 71 72 |
# File 'lib/one_apm/rack/middleware_wrapper.rb', line 70 def determine_prefix OneApm::TransactionNamer.prefix_for_category(nil, @category) end |