Module: Langfuse::ExperimentAttributes Private

Defined in:
lib/langfuse/experiment_attributes.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Builds the OpenTelemetry attributes that identify v4 experiment observations.

Constant Summary collapse

ENVIRONMENT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"sdk-experiment"

Class Method Summary collapse

Class Method Details

.generate_experiment_idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/langfuse/experiment_attributes.rb', line 13

def self.generate_experiment_id
  SecureRandom.hex(8)
end

.generate_item_id(input) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
# File 'lib/langfuse/experiment_attributes.rb', line 17

def self.generate_item_id(input)
  serialized_input = OtelAttributes.serialize(input, preserve_strings: true) || input.to_s
  Digest::SHA256.hexdigest(serialized_input)[0, 16]
end

.observation_metadata(name:, run_name:, experiment_metadata:, item_metadata:, dataset_id: nil, dataset_item_id: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
52
53
54
55
# File 'lib/langfuse/experiment_attributes.rb', line 47

def self.(name:, run_name:, experiment_metadata:, item_metadata:,
                              dataset_id: nil, dataset_item_id: nil)
   = ().merge(())
  [:experiment_name] = name
  [:experiment_run_name] = run_name
  [:dataset_id] = dataset_id if dataset_id
  [:dataset_item_id] = dataset_item_id if dataset_item_id
  
end

.propagated(experiment_id:, run_name:, item_id:, root_observation_id:, dataset_id: nil, experiment_metadata: nil, item_metadata: nil, mask: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ParameterLists



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/langfuse/experiment_attributes.rb', line 23

def self.propagated(experiment_id:, run_name:, item_id:, root_observation_id:,
                    dataset_id: nil, experiment_metadata: nil, item_metadata: nil, mask: nil)
  attributes = {
    OtelAttributes::EXPERIMENT_ID => experiment_id,
    OtelAttributes::EXPERIMENT_NAME => run_name,
    OtelAttributes::EXPERIMENT_DATASET_ID => dataset_id,
    OtelAttributes::EXPERIMENT_ITEM_ID => item_id,
    OtelAttributes::EXPERIMENT_ITEM_ROOT_OBSERVATION_ID => root_observation_id,
    OtelAttributes::ENVIRONMENT => ENVIRONMENT
  }.compact
  attributes.merge!((, OtelAttributes::EXPERIMENT_METADATA, mask))
  attributes.merge!((, OtelAttributes::EXPERIMENT_ITEM_METADATA, mask))
end

.root(description:, expected_output:, mask: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists



38
39
40
41
42
43
44
45
# File 'lib/langfuse/experiment_attributes.rb', line 38

def self.root(description:, expected_output:, mask: nil)
  masked_output = Masking.apply(expected_output, mask: mask)
  {
    OtelAttributes::EXPERIMENT_DESCRIPTION => description,
    OtelAttributes::EXPERIMENT_ITEM_EXPECTED_OUTPUT =>
      OtelAttributes.serialize(masked_output, preserve_strings: true)
  }.compact
end