Module: OrangeTap
- Defined in:
- lib/orange_tap.rb,
lib/orange_tap/event.rb,
lib/orange_tap/config.rb,
lib/orange_tap/worker.rb,
lib/orange_tap/session.rb,
lib/orange_tap/version.rb,
lib/orange_tap/pending_span.rb,
lib/orange_tap/builtin_filter.rb,
lib/orange_tap/otel_converter.rb,
lib/orange_tap/method_registry.rb,
sig/orange_tap.rbs
Defined Under Namespace
Modules: OtelConverter Classes: AlreadyOpenError, BuiltinFilter, Config, Error, Event, MethodRegistry, NotOpenError, PendingSpan, Session, UntraceableMethodError, Worker
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
- .config ⇒ Config
- .default_registry ⇒ MethodRegistry
-
.new(**opts) ⇒ Session
OrangeTap.new -> Session, so
tape = OrangeTap.new; tape.open; ...; tape.stopreads like constructing a recorder, while OrangeTap itself stays a module. -
.open(name = nil, &block) ⇒ void
Block form returns the output path; blockless form returns the Session.
-
.record(name = nil, on_output: nil, **config_overrides) { ... } ⇒ String?
Runs the block in a single session, applying config_overrides for its duration (restored afterwards, even on error) and delivering the output path to on_output on both success and failure.
- .trace_all_instance_methods(klass) ⇒ void
-
.trace_method(*method_objs) ⇒ void
Accepts one or more Method/UnboundMethod objects, or notation strings ("Foo.bar" for a class/singleton method, "Foo#bar" for an instance method), and registers them all in a single call.
- .untrace_method(*method_objs) ⇒ void
Class Method Details
.default_registry ⇒ MethodRegistry
27 28 29 |
# File 'lib/orange_tap.rb', line 27 def default_registry @default_registry ||= MethodRegistry.new end |
.new(**opts) ⇒ Session
OrangeTap.new -> Session, so tape = OrangeTap.new; tape.open; ...; tape.stop
reads like constructing a recorder, while OrangeTap itself stays a module.
23 24 25 |
# File 'lib/orange_tap.rb', line 23 def new(**opts) Session.new(**opts) end |
.open(name = nil, &block) ⇒ void
This method returns an undefined value.
Block form returns the output path; blockless form returns the Session.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'sig/orange_tap.rbs', line 32 def open(name = nil, &block) tape = new tape.open(name) return tape unless block begin block.call tape.stop rescue Exception # rubocop:disable Lint/RescueException # Make sure TracePoints are disabled and the worker is drained even # when the block raises. The output path is unrecoverable here, so we # re-raise the original error instead of returning it. begin tape.stop rescue StandardError nil end raise end end |
.record(name = nil, on_output: nil, **config_overrides) { ... } ⇒ String?
Runs the block in a single session, applying config_overrides for its duration (restored afterwards, even on error) and delivering the output path to on_output on both success and failure. Returns the path on success.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/orange_tap.rb', line 91 def record(name = nil, on_output: nil, **config_overrides) previous = config_overrides.to_h { |key, _| [key, config.public_send(key)] } config_overrides.each { |key, value| config.public_send("#{key}=", value) } tape = new tape.open(name) path = nil begin yield path = tape.stop rescue Exception # rubocop:disable Lint/RescueException path = begin tape.stop rescue StandardError nil end raise ensure previous.each { |key, value| config.public_send("#{key}=", value) } begin on_output&.call(path) rescue StandardError nil end end path end |
.trace_all_instance_methods(klass) ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'lib/orange_tap.rb', line 46 def trace_all_instance_methods(klass) default_registry.register_all_instance_methods(klass) end |
.trace_method(*method_objs) ⇒ void
This method returns an undefined value.
Accepts one or more Method/UnboundMethod objects, or notation strings ("Foo.bar" for a class/singleton method, "Foo#bar" for an instance method), and registers them all in a single call.
38 39 40 |
# File 'lib/orange_tap.rb', line 38 def trace_method(*method_objs) default_registry.register(*method_objs) end |
.untrace_method(*method_objs) ⇒ void
This method returns an undefined value.
42 43 44 |
# File 'lib/orange_tap.rb', line 42 def untrace_method(*method_objs) default_registry.unregister(*method_objs) end |