Skip to content

Create Langfuse::Types module with observation types and attribute classes #6

@kxzk

Description

@kxzk

Overview

Define observation type constants and attributes as the foundation for Langfuse domain models.

Context

  • JS SDK defines observation types in packages/tracing/src/types.ts (lines 12-22)
  • Attributes are typed as LangfuseSpanAttributes, LangfuseGenerationAttributes, etc.
  • Ruby equivalent should use classes/modules for type safety

Technical Implementation

Create lib/langfuse/types.rb with:

Observation Type Constants

module Langfuse
  module Types
    OBSERVATION_TYPES = %w[
      span generation event embedding
      agent tool chain retriever
      evaluator guardrail
    ].freeze

    LEVELS = %w[DEBUG DEFAULT WARNING ERROR].freeze
  end
end

Attribute Classes

Base SpanAttributes:

  • input, output, metadata, level
  • status_message, version, environment
  • #initialize(**kwargs) for keyword arg initialization
  • #to_h for hash representation

GenerationAttributes (extends SpanAttributes):

  • Additional: completion_start_time, model, model_parameters
  • usage_details, cost_details, prompt
  • Prompt should be hash: { name:, version:, is_fallback: }

EmbeddingAttributes (extends GenerationAttributes)

TraceAttributes:

  • name, user_id, session_id, version, release
  • input, output, metadata, tags, public, environment
  • Same initialization pattern

Aliases for Span-like Types

EventAttributes = SpanAttributes
AgentAttributes = SpanAttributes
ToolAttributes = SpanAttributes
ChainAttributes = SpanAttributes
RetrieverAttributes = SpanAttributes
EvaluatorAttributes = SpanAttributes
GuardrailAttributes = SpanAttributes

Acceptance Criteria

  • Langfuse::Types::OBSERVATION_TYPES contains all 10 types
  • Langfuse::Types::SpanAttributes can be instantiated with keyword args
  • Langfuse::Types::GenerationAttributes extends SpanAttributes
  • #to_h returns hash representation of attributes
  • All attribute classes documented with YARD
  • Unit tests for each attribute class

Files to Create

  • lib/langfuse/types.rb - Type definitions
  • spec/langfuse/types_spec.rb - Tests

Dependencies

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions