/*
* server
*
* ## 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`
*
* The version of the OpenAPI document:
*
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
/// ObservationV2 : An observation from the v2 API with field-group-based selection. Core fields are always present. Other fields are included only when their field group is requested.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct ObservationV2 {
/// The unique identifier of the observation
#[serde(rename = "id")]
pub id: String,
/// The trace ID associated with the observation
#[serde(rename = "traceId", deserialize_with = "Option::deserialize")]
pub trace_id: Option<String>,
/// The start time of the observation
#[serde(rename = "startTime")]
pub start_time: chrono::DateTime<chrono::FixedOffset>,
/// The end time of the observation
#[serde(rename = "endTime", deserialize_with = "Option::deserialize")]
pub end_time: Option<chrono::DateTime<chrono::FixedOffset>>,
/// The project ID this observation belongs to
#[serde(rename = "projectId")]
pub project_id: String,
/// The physical parent observation ID, if present. Observations marked as app roots by the SDK may retain a non-null parent ID.
#[serde(
rename = "parentObservationId",
deserialize_with = "Option::deserialize"
)]
pub parent_observation_id: Option<String>,
/// The type of the observation (e.g. GENERATION, SPAN, EVENT)
#[serde(rename = "type")]
pub r#type: String,
/// Whether this observation is a logical root. This is true for observations without a physical parent and observations marked as app roots by the SDK.
#[serde(
rename = "isRootObservation",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub is_root_observation: Option<Option<bool>>,
/// The name of the observation
#[serde(
rename = "name",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub name: Option<Option<String>>,
#[serde(rename = "level", skip_serializing_if = "Option::is_none")]
pub level: Option<models::ObservationLevel>,
/// The status message of the observation
#[serde(
rename = "statusMessage",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub status_message: Option<Option<String>>,
/// The version of the observation
#[serde(
rename = "version",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub version: Option<Option<String>>,
/// The environment from which this observation originated
#[serde(
rename = "environment",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub environment: Option<Option<String>>,
/// Whether the observation is bookmarked
#[serde(
rename = "bookmarked",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub bookmarked: Option<Option<bool>>,
/// Whether the observation is public
#[serde(
rename = "public",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub public: Option<Option<bool>>,
/// The user ID associated with the observation
#[serde(
rename = "userId",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub user_id: Option<Option<String>>,
/// The session ID associated with the observation
#[serde(
rename = "sessionId",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub session_id: Option<Option<String>>,
/// The completion start time of the observation
#[serde(
rename = "completionStartTime",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub completion_start_time: Option<Option<chrono::DateTime<chrono::FixedOffset>>>,
/// The creation timestamp of the observation
#[serde(
rename = "createdAt",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub created_at: Option<Option<chrono::DateTime<chrono::FixedOffset>>>,
/// The last update timestamp of the observation
#[serde(
rename = "updatedAt",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub updated_at: Option<Option<chrono::DateTime<chrono::FixedOffset>>>,
/// The input data of the observation
#[serde(
rename = "input",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub input: Option<Option<serde_json::Value>>,
/// The output data of the observation
#[serde(
rename = "output",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub output: Option<Option<serde_json::Value>>,
/// Additional metadata of the observation
#[serde(
rename = "metadata",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub metadata: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
/// The model name as provided by the user
#[serde(
rename = "model",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub model: Option<Option<String>>,
/// The internal model ID matched by Langfuse
#[serde(
rename = "internalModelId",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub internal_model_id: Option<Option<String>>,
/// The parameters of the model used for the observation
#[serde(
rename = "modelParameters",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub model_parameters: Option<Option<serde_json::Value>>,
/// The usage details of the observation. Key is the usage metric name, value is the number of units consumed.
#[serde(
rename = "usageDetails",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub usage_details: Option<Option<std::collections::HashMap<String, i32>>>,
/// The cost details of the observation. Key is the cost metric name, value is the cost in USD.
#[serde(
rename = "costDetails",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub cost_details: Option<Option<std::collections::HashMap<String, f64>>>,
/// The total cost of the observation in USD
#[serde(
rename = "totalCost",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub total_cost: Option<Option<f64>>,
/// The name of the pricing tier applied to this observation's usage costs
#[serde(
rename = "usagePricingTierName",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub usage_pricing_tier_name: Option<Option<String>>,
/// The prompt ID associated with the observation
#[serde(
rename = "promptId",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub prompt_id: Option<Option<String>>,
/// The prompt name associated with the observation
#[serde(
rename = "promptName",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub prompt_name: Option<Option<String>>,
/// The prompt version associated with the observation
#[serde(
rename = "promptVersion",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub prompt_version: Option<Option<i32>>,
/// The latency in seconds
#[serde(
rename = "latency",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub latency: Option<Option<f64>>,
/// The time to first token in seconds
#[serde(
rename = "timeToFirstToken",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub time_to_first_token: Option<Option<f64>>,
/// The matched model ID. Null when the `model` field group is not requested.
#[serde(rename = "modelId", deserialize_with = "Option::deserialize")]
pub model_id: Option<String>,
/// The input token price (USD per unit) from the matched model, serialized as a decimal string (e.g. \"0.0001\"). Null when the `model` field group is not requested.
#[serde(rename = "inputPrice", deserialize_with = "Option::deserialize")]
pub input_price: Option<String>,
/// The output token price (USD per unit) from the matched model, serialized as a decimal string (e.g. \"0.0001\"). Null when the `model` field group is not requested.
#[serde(rename = "outputPrice", deserialize_with = "Option::deserialize")]
pub output_price: Option<String>,
/// The total token price (USD per unit) from the matched model, serialized as a decimal string (e.g. \"0.0001\"). Null when the `model` field group is not requested.
#[serde(rename = "totalPrice", deserialize_with = "Option::deserialize")]
pub total_price: Option<String>,
/// The name of the parent trace
#[serde(
rename = "traceName",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub trace_name: Option<Option<String>>,
/// Tags from the parent trace (denormalized onto the observation)
#[serde(
rename = "tags",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub tags: Option<Option<Vec<String>>>,
/// The release version of the parent trace
#[serde(
rename = "release",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub release: Option<Option<String>>,
}
impl ObservationV2 {
/// An observation from the v2 API with field-group-based selection. Core fields are always present. Other fields are included only when their field group is requested.
pub fn new(
id: String,
trace_id: Option<String>,
start_time: chrono::DateTime<chrono::FixedOffset>,
end_time: Option<chrono::DateTime<chrono::FixedOffset>>,
project_id: String,
parent_observation_id: Option<String>,
r#type: String,
model_id: Option<String>,
input_price: Option<String>,
output_price: Option<String>,
total_price: Option<String>,
) -> ObservationV2 {
ObservationV2 {
id,
trace_id,
start_time,
end_time,
project_id,
parent_observation_id,
r#type,
is_root_observation: None,
name: None,
level: None,
status_message: None,
version: None,
environment: None,
bookmarked: None,
public: None,
user_id: None,
session_id: None,
completion_start_time: None,
created_at: None,
updated_at: None,
input: None,
output: None,
metadata: None,
model: None,
internal_model_id: None,
model_parameters: None,
usage_details: None,
cost_details: None,
total_cost: None,
usage_pricing_tier_name: None,
prompt_id: None,
prompt_name: None,
prompt_version: None,
latency: None,
time_to_first_token: None,
model_id,
input_price,
output_price,
total_price,
trace_name: None,
tags: None,
release: None,
}
}
}