Class: Langfuse::Span

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

Overview

General-purpose observation for tracking operations, functions, or logical units of work.

Examples:

Block-based API

Langfuse.observe("data-processing", input: { query: "test" }) do |span|
  result = process_data
  span.update(output: result, metadata: { duration_ms: 150 })
end

Stateful API

span = Langfuse.start_observation("data-processing", input: { query: "test" })
result = process_data
span.update(output: result)
span.end

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) ⇒ Span

Returns a new instance of Span.

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



282
283
284
# File 'lib/langfuse/observations.rb', line 282

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

Instance Method Details

#update(attrs) ⇒ self

Parameters:

Returns:

  • (self)


288
289
290
291
# File 'lib/langfuse/observations.rb', line 288

def update(attrs)
  update_observation_attributes(attrs)
  self
end