Class: Observ::ChatInstrumenter
- Inherits:
-
Object
- Object
- Observ::ChatInstrumenter
- Defined in:
- app/services/observ/chat_instrumenter.rb
Instance Attribute Summary collapse
-
#chat ⇒ Object
readonly
Returns the value of attribute chat.
-
#current_tool_span ⇒ Object
readonly
Returns the value of attribute current_tool_span.
-
#current_trace ⇒ Object
readonly
Returns the value of attribute current_trace.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #create_trace(name: "chat_exchange", input: nil, metadata: {}) ⇒ Object
- #finalize_current_trace(output: nil) ⇒ Object
-
#initialize(session, chat, context: {}) ⇒ ChatInstrumenter
constructor
A new instance of ChatInstrumenter.
- #instrument! ⇒ Object
Constructor Details
#initialize(session, chat, context: {}) ⇒ ChatInstrumenter
Returns a new instance of ChatInstrumenter.
7 8 9 10 11 12 13 14 15 16 |
# File 'app/services/observ/chat_instrumenter.rb', line 7 def initialize(session, chat, context: {}) @session = session @chat = chat @context = context @current_trace = nil @current_tool_span = nil @original_ask_method = nil @original_complete_method = nil @instrumented = false end |
Instance Attribute Details
#chat ⇒ Object (readonly)
Returns the value of attribute chat.
5 6 7 |
# File 'app/services/observ/chat_instrumenter.rb', line 5 def chat @chat end |
#current_tool_span ⇒ Object (readonly)
Returns the value of attribute current_tool_span.
5 6 7 |
# File 'app/services/observ/chat_instrumenter.rb', line 5 def current_tool_span @current_tool_span end |
#current_trace ⇒ Object (readonly)
Returns the value of attribute current_trace.
5 6 7 |
# File 'app/services/observ/chat_instrumenter.rb', line 5 def current_trace @current_trace end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
5 6 7 |
# File 'app/services/observ/chat_instrumenter.rb', line 5 def session @session end |
Instance Method Details
#create_trace(name: "chat_exchange", input: nil, metadata: {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/services/observ/chat_instrumenter.rb', line 29 def create_trace(name: "chat_exchange", input: nil, metadata: {}) @current_trace = session.create_trace( name: name, input: input, metadata: @context.merge() ) end |
#finalize_current_trace(output: nil) ⇒ Object
37 38 39 40 41 42 |
# File 'app/services/observ/chat_instrumenter.rb', line 37 def finalize_current_trace(output: nil) return unless @current_trace @current_trace.finalize(output: output) @current_trace = nil end |
#instrument! ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/observ/chat_instrumenter.rb', line 18 def instrument! return if @instrumented wrap_ask_method wrap_complete_method setup_event_handlers @instrumented = true Rails.logger.info "[Observability] Instrumented chat for session #{session.session_id}" end |