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.
272 273 274 275 276 |
# File 'lib/dspy/teleprompt/gepa.rb', line 272 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.
279 280 281 |
# File 'lib/dspy/teleprompt/gepa.rb', line 279 def traces @traces end |
Instance Method Details
#clear ⇒ Object
339 340 341 |
# File 'lib/dspy/teleprompt/gepa.rb', line 339 def clear @traces_mutex.synchronize { @traces.clear } end |
#collect_trace(event_name, event_data) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/dspy/teleprompt/gepa.rb', line 289 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
283 284 285 |
# File 'lib/dspy/teleprompt/gepa.rb', line 283 def collected_count @traces_mutex.synchronize { @traces.size } end |
#llm_traces ⇒ Object
327 328 329 |
# File 'lib/dspy/teleprompt/gepa.rb', line 327 def llm_traces @traces_mutex.synchronize { @traces.select(&:llm_trace?) } end |
#module_traces ⇒ Object
333 334 335 |
# File 'lib/dspy/teleprompt/gepa.rb', line 333 def module_traces @traces_mutex.synchronize { @traces.select(&:module_trace?) } end |
#traces_for_run(run_id) ⇒ Object
316 317 318 319 320 321 322 323 |
# File 'lib/dspy/teleprompt/gepa.rb', line 316 def traces_for_run(run_id) @traces_mutex.synchronize do @traces.select do |trace| = trace. && [:optimization_run_id] == run_id end end end |