Class: Bitfab::BitfabFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/bitfab/client.rb

Overview

Fluent wrapper bound to a single trace_function_key. Mirrors ‘BitfabFunction` in the Python SDK and `BitfabFunction` in the TypeScript SDK — lets callers wrap multiple methods without repeating the key.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, trace_function_key) ⇒ BitfabFunction

Returns a new instance of BitfabFunction.



467
468
469
470
# File 'lib/bitfab/client.rb', line 467

def initialize(client, trace_function_key)
  @client = client
  @trace_function_key = trace_function_key
end

Instance Attribute Details

#trace_function_keyObject (readonly)

Returns the value of attribute trace_function_key.



465
466
467
# File 'lib/bitfab/client.rb', line 465

def trace_function_key
  @trace_function_key
end

Instance Method Details

#wrap(klass, method_name, name: nil, type: "custom", mock_on_replay: false) ⇒ Object

Wrap an existing method on a class with span tracing, binding this function’s trace_function_key.

Routes spans through the client this function was created from (matches Python’s ‘BitfabFunction.span()` using `self._client.span(…)` and TypeScript’s ‘BitfabFunction.withSpan()` using `this.client.withSpan(…)`), so non-global `Bitfab::Client` instances don’t silently fall back to ‘Bitfab.client`.

Examples:

fn = Bitfab.client.get_function("openai")
fn.wrap(OpenAI::Client, :chat, name: "Chat", type: "llm")

Parameters:

  • klass (Class, Module)

    the class to wrap

  • method_name (Symbol)

    the method to wrap

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

    explicit span name (defaults to method name)

  • type (String) (defaults to: "custom")

    span type

  • mock_on_replay (Boolean) (defaults to: false)

    mark this span for the “marked” mock strategy



490
491
492
493
494
495
496
497
# File 'lib/bitfab/client.rb', line 490

def wrap(klass, method_name, name: nil, type: "custom", mock_on_replay: false)
  Bitfab::Traceable.wrap(
    klass, method_name,
    trace_function_key: @trace_function_key,
    name:, type:, mock_on_replay:,
    client: @client
  )
end