Class: OpenTracing::Instrumentation::ObjectWrapper
- Inherits:
-
Object
- Object
- OpenTracing::Instrumentation::ObjectWrapper
- Defined in:
- lib/opentracing/instrumentation/object_wrapper.rb
Overview
ObjectWrapper allow trace call methods on any ruby object.
Usage:
wrapped_object = OpenTracing::Instrumentation::ObjectWrapper.new(other_object)
wrapped_object.other_object_method
Constant Summary collapse
- DEFAULT_OPERATOIN_NAME_PATTERN =
'object_call(%<class_name>s#%<method>s)'
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
wrapped object.
-
#operation_name_pattern ⇒ Object
readonly
Returns the value of attribute operation_name_pattern.
-
#tracer ⇒ Object
readonly
Returns the value of attribute tracer.
Instance Method Summary collapse
-
#initialize(object, tracer: OpenTracing.global_tracer, operation_name_pattern: DEFAULT_OPERATOIN_NAME_PATTERN) ⇒ ObjectWrapper
constructor
A new instance of ObjectWrapper.
- #method_missing(method_name, *args) ⇒ Object
- #respond_to_missing?(method_name) ⇒ Boolean
Constructor Details
#initialize(object, tracer: OpenTracing.global_tracer, operation_name_pattern: DEFAULT_OPERATOIN_NAME_PATTERN) ⇒ ObjectWrapper
Returns a new instance of ObjectWrapper.
17 18 19 20 21 22 23 24 25 |
# File 'lib/opentracing/instrumentation/object_wrapper.rb', line 17 def initialize( object, tracer: OpenTracing.global_tracer, operation_name_pattern: DEFAULT_OPERATOIN_NAME_PATTERN ) @object = object @tracer = tracer @operation_name_pattern = operation_name_pattern end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/opentracing/instrumentation/object_wrapper.rb', line 34 def method_missing(method_name, *args) return super unless object.respond_to?(method_name) operation_name = buid_operation_name(method_name) = (method_name) tracer.start_active_span(operation_name, tags: ) do |scope| call_method(scope.span, method_name, *args) end end |
Instance Attribute Details
#object ⇒ Object (readonly)
wrapped object
28 29 30 |
# File 'lib/opentracing/instrumentation/object_wrapper.rb', line 28 def object @object end |
#operation_name_pattern ⇒ Object (readonly)
Returns the value of attribute operation_name_pattern.
14 15 16 |
# File 'lib/opentracing/instrumentation/object_wrapper.rb', line 14 def operation_name_pattern @operation_name_pattern end |
#tracer ⇒ Object (readonly)
Returns the value of attribute tracer.
14 15 16 |
# File 'lib/opentracing/instrumentation/object_wrapper.rb', line 14 def tracer @tracer end |
Instance Method Details
#respond_to_missing?(method_name) ⇒ Boolean
30 31 32 |
# File 'lib/opentracing/instrumentation/object_wrapper.rb', line 30 def respond_to_missing?(method_name, *) object.respond_to?(method_name) end |