/*
* 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};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct Observation {
/// 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 type of the observation
#[serde(rename = "type")]
pub r#type: String,
/// The name of the observation
#[serde(rename = "name", deserialize_with = "Option::deserialize")]
pub name: 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 completion start time of the observation
#[serde(
rename = "completionStartTime",
deserialize_with = "Option::deserialize"
)]
pub completion_start_time: Option<chrono::DateTime<chrono::FixedOffset>>,
/// The model used for the observation
#[serde(rename = "model", deserialize_with = "Option::deserialize")]
pub model: Option<String>,
/// The parameters of the model used for the observation
#[serde(rename = "modelParameters", deserialize_with = "Option::deserialize")]
pub model_parameters: Option<serde_json::Value>,
/// The input data of the observation
#[serde(rename = "input", deserialize_with = "Option::deserialize")]
pub input: Option<serde_json::Value>,
/// The version of the observation
#[serde(rename = "version", deserialize_with = "Option::deserialize")]
pub version: Option<String>,
/// Additional metadata of the observation
#[serde(rename = "metadata")]
pub metadata: std::collections::HashMap<String, serde_json::Value>,
/// The output data of the observation
#[serde(rename = "output", deserialize_with = "Option::deserialize")]
pub output: Option<serde_json::Value>,
#[serde(rename = "usage")]
pub usage: Box<models::Usage>,
#[serde(rename = "level")]
pub level: models::ObservationLevel,
/// The status message of the observation
#[serde(rename = "statusMessage", deserialize_with = "Option::deserialize")]
pub status_message: Option<String>,
/// The parent observation ID
#[serde(
rename = "parentObservationId",
deserialize_with = "Option::deserialize"
)]
pub parent_observation_id: Option<String>,
/// The prompt ID associated with the observation
#[serde(rename = "promptId", deserialize_with = "Option::deserialize")]
pub prompt_id: Option<String>,
/// 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.
#[serde(rename = "usageDetails")]
pub usage_details: std::collections::HashMap<String, i32>,
/// 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.
#[serde(rename = "costDetails")]
pub cost_details: std::collections::HashMap<String, f64>,
/// The environment from which this observation originated. Can be any lowercase alphanumeric string with hyphens and underscores that does not start with 'langfuse'.
#[serde(rename = "environment")]
pub environment: String,
}
impl Observation {
pub fn new(
id: String,
trace_id: Option<String>,
r#type: String,
name: Option<String>,
start_time: chrono::DateTime<chrono::FixedOffset>,
end_time: Option<chrono::DateTime<chrono::FixedOffset>>,
completion_start_time: Option<chrono::DateTime<chrono::FixedOffset>>,
model: Option<String>,
model_parameters: Option<serde_json::Value>,
input: Option<serde_json::Value>,
version: Option<String>,
metadata: std::collections::HashMap<String, serde_json::Value>,
output: Option<serde_json::Value>,
usage: models::Usage,
level: models::ObservationLevel,
status_message: Option<String>,
parent_observation_id: Option<String>,
prompt_id: Option<String>,
usage_details: std::collections::HashMap<String, i32>,
cost_details: std::collections::HashMap<String, f64>,
environment: String,
) -> Observation {
Observation {
id,
trace_id,
r#type,
name,
start_time,
end_time,
completion_start_time,
model,
model_parameters,
input,
version,
metadata,
output,
usage: Box::new(usage),
level,
status_message,
parent_observation_id,
prompt_id,
usage_details,
cost_details,
environment,
}
}
}