Class: DSPy::Teleprompt::GEPA::TraceCollector
- Inherits:
-
Object
- Object
- DSPy::Teleprompt::GEPA::TraceCollector
- Extended by:
- T::Sig
- Includes:
- Events::SubscriberMixin
- Defined in:
- lib/dspy/teleprompt/gepa.rb
Overview
TraceCollector aggregates execution traces from DSPy events Uses SubscriberMixin for class-level event subscriptions
Instance Attribute Summary collapse
-
#traces ⇒ Object
readonly
Returns the value of attribute traces.
Instance Method Summary collapse
- #clear ⇒ Object
- #collect_trace(event_name, event_data) ⇒ Object
- #collected_count ⇒ Object
-
#initialize ⇒ TraceCollector
constructor
A new instance of TraceCollector.
- #llm_traces ⇒ Object
- #module_traces ⇒ Object
- #traces_for_run(run_id) ⇒ Object
Methods included from Events::SubscriberMixin
Constructor Details
#initialize ⇒ TraceCollector
Returns a new instance of TraceCollector.
273 274 275 276 277 |
# File 'lib/dspy/teleprompt/gepa.rb', line 273 def initialize @traces = T.let([], T::Array[ExecutionTrace]) @traces_mutex = T.let(Mutex.new, Mutex) setup_subscriptions end |
Instance Attribute Details
#traces ⇒ Object (readonly)
Returns the value of attribute traces.
280 281 282 |
# File 'lib/dspy/teleprompt/gepa.rb', line 280 def traces @traces end |
Instance Method Details
#clear ⇒ Object
340 341 342 |
# File 'lib/dspy/teleprompt/gepa.rb', line 340 def clear @traces_mutex.synchronize { @traces.clear } end |
#collect_trace(event_name, event_data) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/dspy/teleprompt/gepa.rb', line 290 def collect_trace(event_name, event_data) @traces_mutex.synchronize do trace_id = event_data['trace_id'] || event_data[:trace_id] || generate_trace_id # Avoid duplicates return if @traces.any? { |t| t.trace_id == trace_id } = event_data['timestamp'] || event_data[:timestamp] || Time.now span_id = event_data['span_id'] || event_data[:span_id] attributes = event_data['attributes'] || event_data[:attributes] || {} = event_data['metadata'] || event_data[:metadata] || {} trace = ExecutionTrace.new( trace_id: trace_id, event_name: event_name, timestamp: , span_id: span_id, attributes: attributes, metadata: ) @traces << trace end end |
#collected_count ⇒ Object
284 285 286 |
# File 'lib/dspy/teleprompt/gepa.rb', line 284 def collected_count @traces_mutex.synchronize { @traces.size } end |
#llm_traces ⇒ Object
328 329 330 |
# File 'lib/dspy/teleprompt/gepa.rb', line 328 def llm_traces @traces_mutex.synchronize { @traces.select(&:llm_trace?) } end |
#module_traces ⇒ Object
334 335 336 |
# File 'lib/dspy/teleprompt/gepa.rb', line 334 def module_traces @traces_mutex.synchronize { @traces.select(&:module_trace?) } end |
#traces_for_run(run_id) ⇒ Object
317 318 319 320 321 322 323 324 |
# File 'lib/dspy/teleprompt/gepa.rb', line 317 def traces_for_run(run_id) @traces_mutex.synchronize do @traces.select do |trace| = trace. && [:optimization_run_id] == run_id end end end |