Module: Langfuse::ReadApi
- Included in:
- ApiClient
- Defined in:
- lib/langfuse/read_api.rb
Overview
The v2 observations and metrics endpoints require Langfuse v4. There is no fallback to legacy endpoints because their response and pagination semantics differ.
Read endpoints for the current Langfuse query surface.
Implements v2 observation and metrics reads plus the v3 scores read.
Mixed into ApiClient, whose private request helper provides HTTP
transport and error handling.
Instance Method Summary collapse
-
#list_observations(from_start_time: nil, to_start_time: nil, trace_id: nil, fields: nil, cursor: nil, limit: nil, filter: nil, name: nil, user_id: nil, type: nil, level: nil, parent_observation_id: nil, is_root_observation: nil, environment: nil, session_id: nil, version: nil, expand_metadata: nil) ⇒ Hash
List observations with cursor-based pagination and field selection.
-
#list_scores(limit: nil, cursor: nil, fields: nil, id: nil, name: nil, source: nil, data_type: nil, environment: nil, config_id: nil, queue_id: nil, author_user_id: nil, value: nil, value_min: nil, value_max: nil, trace_id: nil, session_id: nil, observation_id: nil, experiment_id: nil, from_timestamp: nil, to_timestamp: nil) ⇒ Hash
List scores with polymorphic values (v3).
-
#query_metrics(query:) ⇒ Hash
Query aggregate metrics on Langfuse v4.
Instance Method Details
#list_observations(from_start_time: nil, to_start_time: nil, trace_id: nil, fields: nil, cursor: nil, limit: nil, filter: nil, name: nil, user_id: nil, type: nil, level: nil, parent_observation_id: nil, is_root_observation: nil, environment: nil, session_id: nil, version: nil, expand_metadata: nil) ⇒ Hash
List observations with cursor-based pagination and field selection
Delegates to GET /api/public/v2/observations on Langfuse v4.
Returns observation rows, not reconstructed trace objects. The full
response envelope is preserved: "data" holds the observation rows and
"meta" holds the pagination cursor for the next page.
Broad reads must be bounded: unless trace_id narrows the query, both
from_start_time and to_start_time are required.
rubocop:disable Metrics/ParameterLists
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/langfuse/read_api.rb', line 83 def list_observations(from_start_time: nil, to_start_time: nil, trace_id: nil, fields: nil, cursor: nil, limit: nil, filter: nil, name: nil, user_id: nil, type: nil, level: nil, parent_observation_id: nil, is_root_observation: nil, environment: nil, session_id: nil, version: nil, expand_metadata: nil) validate_bounded_observation_read!(trace_id, from_start_time, to_start_time) params = build_observations_params( from_start_time: from_start_time, to_start_time: to_start_time, trace_id: trace_id, fields: fields, cursor: cursor, limit: limit, filter: filter, name: name, user_id: user_id, type: type, level: level, parent_observation_id: parent_observation_id, environment: environment, is_root_observation: is_root_observation, session_id: session_id, version: version, expand_metadata: ) request( :get, "/api/public/v2/observations", params: params, params_encoder: Faraday::FlatParamsEncoder ) end |
#list_scores(limit: nil, cursor: nil, fields: nil, id: nil, name: nil, source: nil, data_type: nil, environment: nil, config_id: nil, queue_id: nil, author_user_id: nil, value: nil, value_min: nil, value_max: nil, trace_id: nil, session_id: nil, observation_id: nil, experiment_id: nil, from_timestamp: nil, to_timestamp: nil) ⇒ Hash
List scores with polymorphic values (v3)
Delegates to GET /api/public/v3/scores. The full response envelope is
preserved: "data" holds score rows and "meta" holds the pagination
cursor. Score values are polymorphic by dataType: NUMERIC scores return
numbers, BOOLEAN scores return booleans, and CATEGORICAL, TEXT, and
CORRECTION scores return strings.
rubocop:disable Metrics/ParameterLists
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/langfuse/read_api.rb', line 172 def list_scores(limit: nil, cursor: nil, fields: nil, id: nil, name: nil, source: nil, data_type: nil, environment: nil, config_id: nil, queue_id: nil, author_user_id: nil, value: nil, value_min: nil, value_max: nil, trace_id: nil, session_id: nil, observation_id: nil, experiment_id: nil, from_timestamp: nil, to_timestamp: nil) params = build_scores_params( limit: limit, cursor: cursor, fields: fields, id: id, name: name, source: source, data_type: data_type, environment: environment, config_id: config_id, queue_id: queue_id, author_user_id: , value: value, value_min: value_min, value_max: value_max, trace_id: trace_id, session_id: session_id, observation_id: observation_id, experiment_id: experiment_id, from_timestamp: , to_timestamp: ) request(:get, "/api/public/v3/scores", params: params) end |
#query_metrics(query:) ⇒ Hash
Query aggregate metrics on Langfuse v4
Delegates to GET /api/public/v2/metrics. Supports the observations,
scores-numeric, scores-categorical, and scores-boolean views.
128 129 130 |
# File 'lib/langfuse/read_api.rb', line 128 def query_metrics(query:) request(:get, "/api/public/v2/metrics", params: { query: encode_metrics_query(query) }) end |