Class: Langfuse::Event

Inherits:
BaseObservation show all
Defined in:
lib/langfuse/observations.rb

Overview

Point-in-time occurrence. Automatically ended when created without a block.

Examples:

Creating an event

Langfuse.observe("user-action", as_type: :event) do |event|
  event.update(input: { action: "button_click", button_id: "submit" })
end

Event without block (auto-ends)

event = Langfuse.start_observation("error-occurred", {
  input: { error: "Connection timeout" },
  level: "error"
}, as_type: :event)
# Event is automatically ended

Instance Attribute Summary

Attributes inherited from BaseObservation

#otel_span, #otel_tracer, #type

Instance Method Summary collapse

Methods inherited from BaseObservation

#current_span, #end, #event, #id, #input=, #level=, #metadata=, #output=, #score_trace, #start_observation, #trace_id, #trace_url, #update_trace

Constructor Details

#initialize(otel_span, otel_tracer, attributes: nil) ⇒ Event

Returns a new instance of Event.

Parameters:

  • otel_span (OpenTelemetry::SDK::Trace::Span)

    The underlying OTel span

  • otel_tracer (OpenTelemetry::SDK::Trace::Tracer)

    The OTel tracer

  • attributes (Hash, Types::SpanAttributes, nil) (defaults to: nil)

    Optional initial attributes



392
393
394
# File 'lib/langfuse/observations.rb', line 392

def initialize(otel_span, otel_tracer, attributes: nil)
  super(otel_span, otel_tracer, attributes: attributes, type: OBSERVATION_TYPES[:event])
end

Instance Method Details

#update(attrs) ⇒ self

Parameters:

Returns:

  • (self)


398
399
400
401
# File 'lib/langfuse/observations.rb', line 398

def update(attrs)
  update_observation_attributes(attrs)
  self
end