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 =

Returns:

  • (String)
"0.2.0"

Class Method Summary collapse

Class Method Details

.configConfig

Returns:



31
32
33
# File 'lib/orange_tap.rb', line 31

def config
  @config ||= Config.new
end

.default_registryMethodRegistry

Returns:



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.

Parameters:

  • opts (Object)

Returns:



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.

Parameters:

  • name (String, nil) (defaults to: nil)


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.

Parameters:

  • name (String, nil) (defaults to: nil)
  • on_output: (^(String?) -> void, nil) (defaults to: nil)
  • config_overrides (Object)

Yields:

Yield Returns:

  • (void)

Returns:

  • (String, nil)


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.

Parameters:

  • klass (Class)


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.

Parameters:

  • method_objs (method_obj)


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.

Parameters:

  • method_objs (method_obj)


42
43
44
# File 'lib/orange_tap.rb', line 42

def untrace_method(*method_objs)
  default_registry.unregister(*method_objs)
end