langfuse_client/apis/
observations_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ObservationsGetError {
22 Status400(serde_json::Value),
23 Status401(serde_json::Value),
24 Status403(serde_json::Value),
25 Status404(serde_json::Value),
26 Status405(serde_json::Value),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ObservationsGetManyError {
34 Status400(serde_json::Value),
35 Status401(serde_json::Value),
36 Status403(serde_json::Value),
37 Status404(serde_json::Value),
38 Status405(serde_json::Value),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn observations_get(configuration: &configuration::Configuration, observation_id: &str) -> Result<models::ObservationsView, Error<ObservationsGetError>> {
45 let p_observation_id = observation_id;
47
48 let uri_str = format!("{}/api/public/observations/{observationId}", configuration.base_path, observationId=crate::apis::urlencode(p_observation_id));
49 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
50
51 if let Some(ref user_agent) = configuration.user_agent {
52 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53 }
54 if let Some(ref auth_conf) = configuration.basic_auth {
55 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
56 };
57
58 let req = req_builder.build()?;
59 let resp = configuration.client.execute(req).await?;
60
61 let status = resp.status();
62 let content_type = resp
63 .headers()
64 .get("content-type")
65 .and_then(|v| v.to_str().ok())
66 .unwrap_or("application/octet-stream");
67 let content_type = super::ContentType::from(content_type);
68
69 if !status.is_client_error() && !status.is_server_error() {
70 let content = resp.text().await?;
71 match content_type {
72 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
73 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ObservationsView`"))),
74 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ObservationsView`")))),
75 }
76 } else {
77 let content = resp.text().await?;
78 let entity: Option<ObservationsGetError> = serde_json::from_str(&content).ok();
79 Err(Error::ResponseError(ResponseContent { status, content, entity }))
80 }
81}
82
83pub async fn observations_get_many(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>, name: Option<&str>, user_id: Option<&str>, r#type: Option<&str>, trace_id: Option<&str>, parent_observation_id: Option<&str>, environment: Option<Vec<String>>, from_start_time: Option<String>, to_start_time: Option<String>, version: Option<&str>) -> Result<models::ObservationsViews, Error<ObservationsGetManyError>> {
85 let p_page = page;
87 let p_limit = limit;
88 let p_name = name;
89 let p_user_id = user_id;
90 let p_type = r#type;
91 let p_trace_id = trace_id;
92 let p_parent_observation_id = parent_observation_id;
93 let p_environment = environment;
94 let p_from_start_time = from_start_time;
95 let p_to_start_time = to_start_time;
96 let p_version = version;
97
98 let uri_str = format!("{}/api/public/observations", configuration.base_path);
99 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
100
101 if let Some(ref param_value) = p_page {
102 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
103 }
104 if let Some(ref param_value) = p_limit {
105 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
106 }
107 if let Some(ref param_value) = p_name {
108 req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
109 }
110 if let Some(ref param_value) = p_user_id {
111 req_builder = req_builder.query(&[("userId", ¶m_value.to_string())]);
112 }
113 if let Some(ref param_value) = p_type {
114 req_builder = req_builder.query(&[("type", ¶m_value.to_string())]);
115 }
116 if let Some(ref param_value) = p_trace_id {
117 req_builder = req_builder.query(&[("traceId", ¶m_value.to_string())]);
118 }
119 if let Some(ref param_value) = p_parent_observation_id {
120 req_builder = req_builder.query(&[("parentObservationId", ¶m_value.to_string())]);
121 }
122 if let Some(ref param_value) = p_environment {
123 req_builder = match "multi" {
124 "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("environment".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
125 _ => req_builder.query(&[("environment", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
126 };
127 }
128 if let Some(ref param_value) = p_from_start_time {
129 req_builder = req_builder.query(&[("fromStartTime", ¶m_value.to_string())]);
130 }
131 if let Some(ref param_value) = p_to_start_time {
132 req_builder = req_builder.query(&[("toStartTime", ¶m_value.to_string())]);
133 }
134 if let Some(ref param_value) = p_version {
135 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
136 }
137 if let Some(ref user_agent) = configuration.user_agent {
138 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
139 }
140 if let Some(ref auth_conf) = configuration.basic_auth {
141 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
142 };
143
144 let req = req_builder.build()?;
145 let resp = configuration.client.execute(req).await?;
146
147 let status = resp.status();
148 let content_type = resp
149 .headers()
150 .get("content-type")
151 .and_then(|v| v.to_str().ok())
152 .unwrap_or("application/octet-stream");
153 let content_type = super::ContentType::from(content_type);
154
155 if !status.is_client_error() && !status.is_server_error() {
156 let content = resp.text().await?;
157 match content_type {
158 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
159 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ObservationsViews`"))),
160 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ObservationsViews`")))),
161 }
162 } else {
163 let content = resp.text().await?;
164 let entity: Option<ObservationsGetManyError> = serde_json::from_str(&content).ok();
165 Err(Error::ResponseError(ResponseContent { status, content, entity }))
166 }
167}
168