Module: Braintrust::Contrib::OpenAI::Instrumentation::Responses::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#create(**params) ⇒ Object

Wrap non-streaming create method



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/braintrust/contrib/openai/instrumentation/responses.rb', line 35

def create(**params)
  client = instance_variable_get(:@client)
  tracer = Braintrust::Contrib.tracer_for(client)

  tracer.in_span("openai.responses.create") do |span|
     = (params)

    set_input(span, params)

    response = nil
    time_to_first_token = Braintrust::Internal::Time.measure do
      response = super
    end

    set_output(span, response)
    set_metrics(span, response, time_to_first_token)
    (span, , response)

    response
  end
end

#stream(**params) ⇒ Object

Wrap streaming method Stores context on stream object for span creation during consumption



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/braintrust/contrib/openai/instrumentation/responses.rb', line 59

def stream(**params)
  client = instance_variable_get(:@client)
  tracer = Braintrust::Contrib.tracer_for(client)
   = (params, stream: true)

  stream_obj = super

  Braintrust::Contrib::Context.set!(stream_obj,
    tracer: tracer,
    params: params,
    metadata: ,
    responses_instance: self)
  stream_obj
end