Class: Langfuse::Types::TraceAttributes

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

Overview

Attributes for Langfuse traces

Traces are the top-level containers that group related observations together. They represent a complete workflow, request, or user interaction.

Examples:

attrs = TraceAttributes.new(
  name: "user-request",
  user_id: "user-123",
  session_id: "session-456",
  input: { query: "What is Ruby?" },
  output: { answer: "Ruby is a programming language" },
  tags: ["api", "v1"],
  public: false
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil, metadata: nil, tags: nil, public: nil, environment: nil) ⇒ TraceAttributes

Initialize a new TraceAttributes instance

rubocop:disable Metrics/ParameterLists

Parameters:

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

    Human-readable name for the trace

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

    User identifier

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

    Session identifier

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

    Version identifier

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

    Release identifier

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

    Input data

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

    Output data

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

    Additional metadata

  • tags (Array<String>, nil) (defaults to: nil)

    Tags array (each tag must be ≤200 characters; oversized tags are dropped)

  • public (Boolean, nil) (defaults to: nil)

    Public visibility flag

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

    Environment identifier



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/langfuse/types.rb', line 294

def initialize(name: nil, user_id: nil, session_id: nil, version: nil, release: nil, input: nil, output: nil,
               metadata: nil, tags: nil, public: nil, environment: nil)
  # rubocop:enable Metrics/ParameterLists
  @name = name
  @user_id = user_id
  @session_id = session_id
  @version = version
  @release = release
  @input = input
  @output = output
  @metadata = 
  @tags = tags
  @public = public
  @environment = environment
end

Instance Attribute Details

#environmentString?

Returns Environment where the trace was captured.

Returns:

  • (String, nil)

    Environment where the trace was captured



278
279
280
# File 'lib/langfuse/types.rb', line 278

def environment
  @environment
end

#inputObject?

Returns Input data that initiated the trace.

Returns:

  • (Object, nil)

    Input data that initiated the trace



263
264
265
# File 'lib/langfuse/types.rb', line 263

def input
  @input
end

#metadataHash?

Returns Additional metadata for the trace.

Returns:

  • (Hash, nil)

    Additional metadata for the trace



269
270
271
# File 'lib/langfuse/types.rb', line 269

def 
  @metadata
end

#nameString?

Returns Human-readable name for the trace.

Returns:

  • (String, nil)

    Human-readable name for the trace



248
249
250
# File 'lib/langfuse/types.rb', line 248

def name
  @name
end

#outputObject?

Returns Final output data from the trace.

Returns:

  • (Object, nil)

    Final output data from the trace



266
267
268
# File 'lib/langfuse/types.rb', line 266

def output
  @output
end

#publicBoolean?

Returns Whether this trace should be publicly visible.

Returns:

  • (Boolean, nil)

    Whether this trace should be publicly visible



275
276
277
# File 'lib/langfuse/types.rb', line 275

def public
  @public
end

#releaseString?

Returns Release identifier for deployment tracking.

Returns:

  • (String, nil)

    Release identifier for deployment tracking



260
261
262
# File 'lib/langfuse/types.rb', line 260

def release
  @release
end

#session_idString?

Returns Session identifier for grouping related traces.

Returns:

  • (String, nil)

    Session identifier for grouping related traces



254
255
256
# File 'lib/langfuse/types.rb', line 254

def session_id
  @session_id
end

#tagsArray<String>?

Returns Tags for categorizing and filtering traces.

Returns:

  • (Array<String>, nil)

    Tags for categorizing and filtering traces



272
273
274
# File 'lib/langfuse/types.rb', line 272

def tags
  @tags
end

#user_idString?

Returns Identifier for the user associated with this trace.

Returns:

  • (String, nil)

    Identifier for the user associated with this trace



251
252
253
# File 'lib/langfuse/types.rb', line 251

def user_id
  @user_id
end

#versionString?

Returns Version identifier for the code/application.

Returns:

  • (String, nil)

    Version identifier for the code/application



257
258
259
# File 'lib/langfuse/types.rb', line 257

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



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/langfuse/types.rb', line 315

def to_h
  {
    name: @name,
    user_id: @user_id,
    session_id: @session_id,
    version: @version,
    release: @release,
    input: @input,
    output: @output,
    metadata: @metadata,
    tags: @tags,
    public: @public,
    environment: @environment
  }.compact
end