Class: Langfuse::Types::SpanAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/langfuse/types.rb

Overview

Attributes for Langfuse span observations

Spans are used to track operations, functions, or logical units of work. They can contain other spans, generations, or events as children.

Examples:

attrs = SpanAttributes.new(
  input: { query: "SELECT * FROM users" },
  output: { count: 42 },
  level: "DEFAULT",
  metadata: { source: "database" }
)
attrs.to_h # => { input: {...}, output: {...}, level: "DEFAULT", metadata: {...} }

Direct Known Subclasses

GenerationAttributes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input: nil, output: nil, metadata: nil, level: nil, status_message: nil, version: nil, environment: nil) ⇒ SpanAttributes

Initialize a new SpanAttributes instance

rubocop:disable Metrics/ParameterLists

Parameters:

  • input (Object, nil) (defaults to: nil)

    Input data for the operation

  • output (Object, nil) (defaults to: nil)

    Output data from the operation

  • metadata (Hash, nil) (defaults to: nil)

    Additional metadata as key-value pairs

  • level (String, nil) (defaults to: nil)

    Severity level (DEBUG, DEFAULT, WARNING, ERROR)

  • status_message (String, nil) (defaults to: nil)

    Human-readable status message

  • version (String, nil) (defaults to: nil)

    Version identifier

  • environment (String, nil) (defaults to: nil)

    Environment identifier



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/langfuse/types.rb', line 118

def initialize(input: nil, output: nil, metadata: nil, level: nil, status_message: nil, version: nil,
               environment: nil)
  # rubocop:enable Metrics/ParameterLists
  @input = input
  @output = output
  @metadata = 
  @level = level
  @status_message = status_message
  @version = version
  @environment = environment
end

Instance Attribute Details

#environmentString?

Returns Environment where the operation is running (e.g., ‘production’, ‘staging’).

Returns:

  • (String, nil)

    Environment where the operation is running (e.g., ‘production’, ‘staging’)



106
107
108
# File 'lib/langfuse/types.rb', line 106

def environment
  @environment
end

#inputObject?

Returns Input data for the operation being tracked.

Returns:

  • (Object, nil)

    Input data for the operation being tracked



88
89
90
# File 'lib/langfuse/types.rb', line 88

def input
  @input
end

#levelString?

Returns Severity level of the observation (DEBUG, DEFAULT, WARNING, ERROR).

Returns:

  • (String, nil)

    Severity level of the observation (DEBUG, DEFAULT, WARNING, ERROR)



97
98
99
# File 'lib/langfuse/types.rb', line 97

def level
  @level
end

#metadataHash?

Returns Additional metadata as key-value pairs.

Returns:

  • (Hash, nil)

    Additional metadata as key-value pairs



94
95
96
# File 'lib/langfuse/types.rb', line 94

def 
  @metadata
end

#outputObject?

Returns Output data from the operation.

Returns:

  • (Object, nil)

    Output data from the operation



91
92
93
# File 'lib/langfuse/types.rb', line 91

def output
  @output
end

#status_messageString?

Returns Human-readable status message.

Returns:

  • (String, nil)

    Human-readable status message



100
101
102
# File 'lib/langfuse/types.rb', line 100

def status_message
  @status_message
end

#versionString?

Returns Version identifier for the code/model being tracked.

Returns:

  • (String, nil)

    Version identifier for the code/model being tracked



103
104
105
# File 'lib/langfuse/types.rb', line 103

def version
  @version
end

Instance Method Details

#to_hHash

Convert attributes to a hash representation

Returns a hash with all non-nil attributes. Nil values are excluded.

Returns:

  • (Hash)

    Hash representation of attributes



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/langfuse/types.rb', line 135

def to_h
  {
    input: @input,
    output: @output,
    metadata: @metadata,
    level: @level,
    status_message: @status_message,
    version: @version,
    environment: @environment
  }.compact
end