Module: Bitfab::Traceable
- Defined in:
- lib/bitfab/traceable.rb
Overview
Mixin for declarative span tracing on instance methods.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .included(base) ⇒ Object
-
.wrap(klass, method_name, trace_function_key:, name: nil, type: "custom", mock_on_replay: false, client: nil) ⇒ Object
Wrap an existing method on an external class with span tracing.
Class Method Details
.included(base) ⇒ Object
25 26 27 |
# File 'lib/bitfab/traceable.rb', line 25 def self.included(base) base.extend(ClassMethods) end |
.wrap(klass, method_name, trace_function_key:, name: nil, type: "custom", mock_on_replay: false, client: nil) ⇒ Object
Wrap an existing method on an external class with span tracing. Use this to trace third-party library calls without modifying their source.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/bitfab/traceable.rb', line 50 def self.wrap(klass, method_name, trace_function_key:, name: nil, type: "custom", mock_on_replay: false, client: nil) span_name = name || method_name.to_s method_name_str = method_name.to_s bound_client = client wrapper = Module.new do define_method(method_name) do |*args, **kwargs, &block| target_client = bound_client || Bitfab.client target_client.send(:execute_span, trace_function_key:, span_name:, span_type: type, function_name: method_name_str, args:, kwargs:, mock_on_replay:) do super(*args, **kwargs, &block) end end end klass.prepend(wrapper) end |