Class: OpenTracing::Instrumentation::ObjectWrapper

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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)
  tags = build_tags(method_name)
  tracer.start_active_span(operation_name, tags: tags) do |scope|
    call_method(scope.span, method_name, *args)
  end
end

Instance Attribute Details

#objectObject (readonly)

wrapped object



28
29
30
# File 'lib/opentracing/instrumentation/object_wrapper.rb', line 28

def object
  @object
end

#operation_name_patternObject (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

#tracerObject (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

Returns:

  • (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