Class: DSPy::Subscribers::LangfuseSubscriber

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dspy/subscribers/langfuse_subscriber.rb

Overview

Langfuse subscriber that provides comprehensive LLM observability for DSPy operations Tracks prompts, completions, optimization traces, and performance metrics

Defined Under Namespace

Classes: LangfuseConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: nil) ⇒ LangfuseSubscriber

Returns a new instance of LangfuseSubscriber.



75
76
77
78
79
80
81
82
83
84
# File 'lib/dspy/subscribers/langfuse_subscriber.rb', line 75

def initialize(config: nil)
  @config = config || LangfuseConfig.new
  @langfuse = T.let(nil, T.nilable(T.untyped))
  @optimization_traces = T.let({}, T::Hash[String, T.untyped])
  @trial_spans = T.let({}, T::Hash[String, T.untyped])
  @lm_generations = T.let({}, T::Hash[String, T.untyped])
  
  setup_langfuse if @config.enabled
  setup_event_subscriptions
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



72
73
74
# File 'lib/dspy/subscribers/langfuse_subscriber.rb', line 72

def config
  @config
end

Instance Method Details

#add_score(trace_id, name, value, comment: nil) ⇒ Object



650
651
652
653
654
655
656
657
658
659
# File 'lib/dspy/subscribers/langfuse_subscriber.rb', line 650

def add_score(trace_id, name, value, comment: nil)
  return unless @langfuse
  
  @langfuse.score(
    trace_id: trace_id,
    name: name,
    value: value,
    comment: comment
  )
end

#create_trace(name, metadata: {}) ⇒ Object



639
640
641
642
643
644
645
646
647
# File 'lib/dspy/subscribers/langfuse_subscriber.rb', line 639

def create_trace(name, metadata: {})
  return nil unless @langfuse
  
  @langfuse.trace(
    name: name,
    metadata: ,
    tags: @config.default_tags
  )
end

#flushObject



662
663
664
665
666
# File 'lib/dspy/subscribers/langfuse_subscriber.rb', line 662

def flush
  return unless @langfuse
  
  @langfuse.flush
end

#langfuse_clientObject



634
635
636
# File 'lib/dspy/subscribers/langfuse_subscriber.rb', line 634

def langfuse_client
  @langfuse
end