Module: Braintrust::Contrib::RubyOpenAI::Instrumentation::Responses

Defined in:
lib/braintrust/contrib/ruby_openai/instrumentation/responses.rb

Overview

Responses API instrumentation for ruby-openai. Provides module that can be prepended to OpenAI::Responses to instrument the create method.

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

METADATA_FIELDS =
%i[
  model instructions modalities tools parallel_tool_calls
  tool_choice temperature max_tokens top_p frequency_penalty
  presence_penalty seed user metadata store response_format
  reasoning previous_response_id truncation
].freeze

Class Method Summary collapse

Class Method Details

.applied?(base) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/braintrust/contrib/ruby_openai/instrumentation/responses.rb', line 28

def self.applied?(base)
  base.ancestors.include?(InstanceMethods)
end

.included(base) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/braintrust/contrib/ruby_openai/instrumentation/responses.rb', line 18

def self.included(base)
  # Guard against double-wrapping: Check if patch is already in the ancestor chain.
  # This prevents double instrumentation if class-level patching was already applied,
  # and this patch is being applied to a singleton-class. (Special case.)
  #
  # Ruby's prepend() doesn't check the full inheritance chain, so without this guard,
  # the instrumentation could be added twice.
  base.prepend(InstanceMethods) unless applied?(base)
end