Skip to main content

langfuse_client_base/models/
observations_view.rs

1/*
2 * server
3 *
4 * ## Real-time data  The only real-time path to get tracing data is to ingest via OpenTelemetry (`POST /api/public/otel/v1/traces`) and retrieve via Observations API v2 (`GET /api/public/v2/observations`) and Metrics API v2 (`GET /api/public/v2/metrics`). Other public API write and read endpoints can delay data by about 10 minutes. Direct OpenTelemetry exporters must send the `x-langfuse-ingestion-version: 4` header; current Python and JS SDKs already do. See the [Public API docs](https://langfuse.com/docs/api-and-data-platform/features/public-api) and [real-time ingestion](https://langfuse.com/integrations/native/opentelemetry.md#real-time-ingestion).  ## Authentication  Authenticate with the API using [Basic Auth](https://en.wikipedia.org/wiki/Basic_access_authentication), get API keys in the project settings:  - username: Langfuse Public Key - password: Langfuse Secret Key  ## Exports  - OpenAPI spec: https://cloud.langfuse.com/generated/api/openapi.yml - Self-hosted deployments: interactive API reference at `/api/docs` and OpenAPI spec at `/api/openapi.yaml`
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
15pub struct ObservationsView {
16    /// The unique identifier of the observation
17    #[serde(rename = "id")]
18    pub id: String,
19    /// The trace ID associated with the observation
20    #[serde(rename = "traceId", deserialize_with = "Option::deserialize")]
21    pub trace_id: Option<String>,
22    /// The type of the observation
23    #[serde(rename = "type")]
24    pub r#type: String,
25    /// The name of the observation
26    #[serde(rename = "name", deserialize_with = "Option::deserialize")]
27    pub name: Option<String>,
28    /// The start time of the observation
29    #[serde(rename = "startTime")]
30    pub start_time: chrono::DateTime<chrono::FixedOffset>,
31    /// The end time of the observation.
32    #[serde(rename = "endTime", deserialize_with = "Option::deserialize")]
33    pub end_time: Option<chrono::DateTime<chrono::FixedOffset>>,
34    /// The completion start time of the observation
35    #[serde(
36        rename = "completionStartTime",
37        deserialize_with = "Option::deserialize"
38    )]
39    pub completion_start_time: Option<chrono::DateTime<chrono::FixedOffset>>,
40    /// The model used for the observation
41    #[serde(rename = "model", deserialize_with = "Option::deserialize")]
42    pub model: Option<String>,
43    /// The parameters of the model used for the observation
44    #[serde(rename = "modelParameters", deserialize_with = "Option::deserialize")]
45    pub model_parameters: Option<serde_json::Value>,
46    /// The input data of the observation
47    #[serde(rename = "input", deserialize_with = "Option::deserialize")]
48    pub input: Option<serde_json::Value>,
49    /// The version of the observation
50    #[serde(rename = "version", deserialize_with = "Option::deserialize")]
51    pub version: Option<String>,
52    /// Additional metadata of the observation
53    #[serde(
54        rename = "metadata",
55        default,
56        with = "::serde_with::rust::double_option",
57        skip_serializing_if = "Option::is_none"
58    )]
59    pub metadata: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
60    /// The output data of the observation
61    #[serde(rename = "output", deserialize_with = "Option::deserialize")]
62    pub output: Option<serde_json::Value>,
63    #[serde(rename = "usage")]
64    pub usage: Box<models::Usage>,
65    #[serde(rename = "level")]
66    pub level: models::ObservationLevel,
67    /// The status message of the observation
68    #[serde(rename = "statusMessage", deserialize_with = "Option::deserialize")]
69    pub status_message: Option<String>,
70    /// The parent observation ID
71    #[serde(
72        rename = "parentObservationId",
73        deserialize_with = "Option::deserialize"
74    )]
75    pub parent_observation_id: Option<String>,
76    /// The prompt ID associated with the observation
77    #[serde(rename = "promptId", deserialize_with = "Option::deserialize")]
78    pub prompt_id: Option<String>,
79    /// The usage details of the observation. Key is the name of the usage metric, value is the number of units consumed. The total key is the sum of all (non-total) usage metrics or the total value ingested.
80    #[serde(rename = "usageDetails")]
81    pub usage_details: std::collections::HashMap<String, i32>,
82    /// The cost details of the observation. Key is the name of the cost metric, value is the cost in USD. The total key is the sum of all (non-total) cost metrics or the total value ingested.
83    #[serde(rename = "costDetails")]
84    pub cost_details: std::collections::HashMap<String, f64>,
85    /// The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
86    #[serde(rename = "environment")]
87    pub environment: String,
88    /// The name of the prompt associated with the observation
89    #[serde(rename = "promptName", deserialize_with = "Option::deserialize")]
90    pub prompt_name: Option<String>,
91    /// The version of the prompt associated with the observation
92    #[serde(rename = "promptVersion", deserialize_with = "Option::deserialize")]
93    pub prompt_version: Option<i32>,
94    /// The unique identifier of the model
95    #[serde(rename = "modelId", deserialize_with = "Option::deserialize")]
96    pub model_id: Option<String>,
97    /// The price of the input in USD
98    #[serde(rename = "inputPrice", deserialize_with = "Option::deserialize")]
99    pub input_price: Option<f64>,
100    /// The price of the output in USD.
101    #[serde(rename = "outputPrice", deserialize_with = "Option::deserialize")]
102    pub output_price: Option<f64>,
103    /// The total price in USD.
104    #[serde(rename = "totalPrice", deserialize_with = "Option::deserialize")]
105    pub total_price: Option<f64>,
106    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the input in USD
107    #[serde(
108        rename = "calculatedInputCost",
109        deserialize_with = "Option::deserialize"
110    )]
111    pub calculated_input_cost: Option<f64>,
112    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated cost of the output in USD
113    #[serde(
114        rename = "calculatedOutputCost",
115        deserialize_with = "Option::deserialize"
116    )]
117    pub calculated_output_cost: Option<f64>,
118    /// (Deprecated. Use usageDetails and costDetails instead.) The calculated total cost in USD
119    #[serde(
120        rename = "calculatedTotalCost",
121        deserialize_with = "Option::deserialize"
122    )]
123    pub calculated_total_cost: Option<f64>,
124    /// The latency in seconds.
125    #[serde(rename = "latency", deserialize_with = "Option::deserialize")]
126    pub latency: Option<f64>,
127    /// The time to the first token in seconds
128    #[serde(rename = "timeToFirstToken", deserialize_with = "Option::deserialize")]
129    pub time_to_first_token: Option<f64>,
130}
131
132impl ObservationsView {
133    pub fn new(
134        id: String,
135        trace_id: Option<String>,
136        r#type: String,
137        name: Option<String>,
138        start_time: chrono::DateTime<chrono::FixedOffset>,
139        end_time: Option<chrono::DateTime<chrono::FixedOffset>>,
140        completion_start_time: Option<chrono::DateTime<chrono::FixedOffset>>,
141        model: Option<String>,
142        model_parameters: Option<serde_json::Value>,
143        input: Option<serde_json::Value>,
144        version: Option<String>,
145        output: Option<serde_json::Value>,
146        usage: models::Usage,
147        level: models::ObservationLevel,
148        status_message: Option<String>,
149        parent_observation_id: Option<String>,
150        prompt_id: Option<String>,
151        usage_details: std::collections::HashMap<String, i32>,
152        cost_details: std::collections::HashMap<String, f64>,
153        environment: String,
154        prompt_name: Option<String>,
155        prompt_version: Option<i32>,
156        model_id: Option<String>,
157        input_price: Option<f64>,
158        output_price: Option<f64>,
159        total_price: Option<f64>,
160        calculated_input_cost: Option<f64>,
161        calculated_output_cost: Option<f64>,
162        calculated_total_cost: Option<f64>,
163        latency: Option<f64>,
164        time_to_first_token: Option<f64>,
165    ) -> ObservationsView {
166        ObservationsView {
167            id,
168            trace_id,
169            r#type,
170            name,
171            start_time,
172            end_time,
173            completion_start_time,
174            model,
175            model_parameters,
176            input,
177            version,
178            metadata: None,
179            output,
180            usage: Box::new(usage),
181            level,
182            status_message,
183            parent_observation_id,
184            prompt_id,
185            usage_details,
186            cost_details,
187            environment,
188            prompt_name,
189            prompt_version,
190            model_id,
191            input_price,
192            output_price,
193            total_price,
194            calculated_input_cost,
195            calculated_output_cost,
196            calculated_total_cost,
197            latency,
198            time_to_first_token,
199        }
200    }
201}