langfuse_client_base/apis/
trace_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum TraceDeleteError {
20 Status400(serde_json::Value),
21 Status401(serde_json::Value),
22 Status403(serde_json::Value),
23 Status404(serde_json::Value),
24 Status405(serde_json::Value),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum TraceDeleteMultipleError {
32 Status400(serde_json::Value),
33 Status401(serde_json::Value),
34 Status403(serde_json::Value),
35 Status404(serde_json::Value),
36 Status405(serde_json::Value),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum TraceGetError {
44 Status400(serde_json::Value),
45 Status401(serde_json::Value),
46 Status403(serde_json::Value),
47 Status404(serde_json::Value),
48 Status405(serde_json::Value),
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum TraceListError {
56 Status400(serde_json::Value),
57 Status401(serde_json::Value),
58 Status403(serde_json::Value),
59 Status404(serde_json::Value),
60 Status405(serde_json::Value),
61 UnknownValue(serde_json::Value),
62}
63
64pub async fn trace_delete(
66 configuration: &configuration::Configuration,
67 trace_id: &str,
68) -> Result<models::DeleteTraceResponse, Error<TraceDeleteError>> {
69 let p_path_trace_id = trace_id;
71
72 let uri_str = format!(
73 "{}/api/public/traces/{traceId}",
74 configuration.base_path,
75 traceId = crate::apis::urlencode(p_path_trace_id)
76 );
77 let mut req_builder = configuration
78 .client
79 .request(reqwest::Method::DELETE, &uri_str);
80
81 if let Some(ref user_agent) = configuration.user_agent {
82 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
83 }
84 if let Some(ref auth_conf) = configuration.basic_auth {
85 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
86 };
87
88 let req = req_builder.build()?;
89 let resp = configuration.client.execute(req).await?;
90
91 let status = resp.status();
92 let content_type = resp
93 .headers()
94 .get("content-type")
95 .and_then(|v| v.to_str().ok())
96 .unwrap_or("application/octet-stream");
97 let content_type = super::ContentType::from(content_type);
98
99 if !status.is_client_error() && !status.is_server_error() {
100 let content = resp.text().await?;
101 match content_type {
102 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
103 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteTraceResponse`"))),
104 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::DeleteTraceResponse`")))),
105 }
106 } else {
107 let content = resp.text().await?;
108 let entity: Option<TraceDeleteError> = serde_json::from_str(&content).ok();
109 Err(Error::ResponseError(ResponseContent {
110 status,
111 content,
112 entity,
113 }))
114 }
115}
116
117pub async fn trace_delete_multiple(
119 configuration: &configuration::Configuration,
120 trace_delete_multiple_request: models::TraceDeleteMultipleRequest,
121) -> Result<models::DeleteTraceResponse, Error<TraceDeleteMultipleError>> {
122 let p_body_trace_delete_multiple_request = trace_delete_multiple_request;
124
125 let uri_str = format!("{}/api/public/traces", configuration.base_path);
126 let mut req_builder = configuration
127 .client
128 .request(reqwest::Method::DELETE, &uri_str);
129
130 if let Some(ref user_agent) = configuration.user_agent {
131 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
132 }
133 if let Some(ref auth_conf) = configuration.basic_auth {
134 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
135 };
136 req_builder = req_builder.json(&p_body_trace_delete_multiple_request);
137
138 let req = req_builder.build()?;
139 let resp = configuration.client.execute(req).await?;
140
141 let status = resp.status();
142 let content_type = resp
143 .headers()
144 .get("content-type")
145 .and_then(|v| v.to_str().ok())
146 .unwrap_or("application/octet-stream");
147 let content_type = super::ContentType::from(content_type);
148
149 if !status.is_client_error() && !status.is_server_error() {
150 let content = resp.text().await?;
151 match content_type {
152 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
153 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteTraceResponse`"))),
154 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::DeleteTraceResponse`")))),
155 }
156 } else {
157 let content = resp.text().await?;
158 let entity: Option<TraceDeleteMultipleError> = serde_json::from_str(&content).ok();
159 Err(Error::ResponseError(ResponseContent {
160 status,
161 content,
162 entity,
163 }))
164 }
165}
166
167pub async fn trace_get(
169 configuration: &configuration::Configuration,
170 trace_id: &str,
171) -> Result<models::TraceWithFullDetails, Error<TraceGetError>> {
172 let p_path_trace_id = trace_id;
174
175 let uri_str = format!(
176 "{}/api/public/traces/{traceId}",
177 configuration.base_path,
178 traceId = crate::apis::urlencode(p_path_trace_id)
179 );
180 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
181
182 if let Some(ref user_agent) = configuration.user_agent {
183 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
184 }
185 if let Some(ref auth_conf) = configuration.basic_auth {
186 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
187 };
188
189 let req = req_builder.build()?;
190 let resp = configuration.client.execute(req).await?;
191
192 let status = resp.status();
193 let content_type = resp
194 .headers()
195 .get("content-type")
196 .and_then(|v| v.to_str().ok())
197 .unwrap_or("application/octet-stream");
198 let content_type = super::ContentType::from(content_type);
199
200 if !status.is_client_error() && !status.is_server_error() {
201 let content = resp.text().await?;
202 match content_type {
203 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
204 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TraceWithFullDetails`"))),
205 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::TraceWithFullDetails`")))),
206 }
207 } else {
208 let content = resp.text().await?;
209 let entity: Option<TraceGetError> = serde_json::from_str(&content).ok();
210 Err(Error::ResponseError(ResponseContent {
211 status,
212 content,
213 entity,
214 }))
215 }
216}
217
218pub async fn trace_list(
220 configuration: &configuration::Configuration,
221 page: Option<i32>,
222 limit: Option<i32>,
223 user_id: Option<&str>,
224 name: Option<&str>,
225 session_id: Option<&str>,
226 from_timestamp: Option<String>,
227 to_timestamp: Option<String>,
228 order_by: Option<&str>,
229 tags: Option<Vec<String>>,
230 version: Option<&str>,
231 release: Option<&str>,
232 environment: Option<Vec<String>>,
233 fields: Option<&str>,
234) -> Result<models::Traces, Error<TraceListError>> {
235 let p_query_page = page;
237 let p_query_limit = limit;
238 let p_query_user_id = user_id;
239 let p_query_name = name;
240 let p_query_session_id = session_id;
241 let p_query_from_timestamp = from_timestamp;
242 let p_query_to_timestamp = to_timestamp;
243 let p_query_order_by = order_by;
244 let p_query_tags = tags;
245 let p_query_version = version;
246 let p_query_release = release;
247 let p_query_environment = environment;
248 let p_query_fields = fields;
249
250 let uri_str = format!("{}/api/public/traces", configuration.base_path);
251 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
252
253 if let Some(ref param_value) = p_query_page {
254 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
255 }
256 if let Some(ref param_value) = p_query_limit {
257 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
258 }
259 if let Some(ref param_value) = p_query_user_id {
260 req_builder = req_builder.query(&[("userId", ¶m_value.to_string())]);
261 }
262 if let Some(ref param_value) = p_query_name {
263 req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
264 }
265 if let Some(ref param_value) = p_query_session_id {
266 req_builder = req_builder.query(&[("sessionId", ¶m_value.to_string())]);
267 }
268 if let Some(ref param_value) = p_query_from_timestamp {
269 req_builder = req_builder.query(&[("fromTimestamp", ¶m_value.to_string())]);
270 }
271 if let Some(ref param_value) = p_query_to_timestamp {
272 req_builder = req_builder.query(&[("toTimestamp", ¶m_value.to_string())]);
273 }
274 if let Some(ref param_value) = p_query_order_by {
275 req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
276 }
277 if let Some(ref param_value) = p_query_tags {
278 req_builder = match "multi" {
279 "multi" => req_builder.query(
280 ¶m_value
281 .into_iter()
282 .map(|p| ("tags".to_owned(), p.to_string()))
283 .collect::<Vec<(std::string::String, std::string::String)>>(),
284 ),
285 _ => req_builder.query(&[(
286 "tags",
287 ¶m_value
288 .into_iter()
289 .map(|p| p.to_string())
290 .collect::<Vec<String>>()
291 .join(",")
292 .to_string(),
293 )]),
294 };
295 }
296 if let Some(ref param_value) = p_query_version {
297 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
298 }
299 if let Some(ref param_value) = p_query_release {
300 req_builder = req_builder.query(&[("release", ¶m_value.to_string())]);
301 }
302 if let Some(ref param_value) = p_query_environment {
303 req_builder = match "multi" {
304 "multi" => req_builder.query(
305 ¶m_value
306 .into_iter()
307 .map(|p| ("environment".to_owned(), p.to_string()))
308 .collect::<Vec<(std::string::String, std::string::String)>>(),
309 ),
310 _ => req_builder.query(&[(
311 "environment",
312 ¶m_value
313 .into_iter()
314 .map(|p| p.to_string())
315 .collect::<Vec<String>>()
316 .join(",")
317 .to_string(),
318 )]),
319 };
320 }
321 if let Some(ref param_value) = p_query_fields {
322 req_builder = req_builder.query(&[("fields", ¶m_value.to_string())]);
323 }
324 if let Some(ref user_agent) = configuration.user_agent {
325 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
326 }
327 if let Some(ref auth_conf) = configuration.basic_auth {
328 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
329 };
330
331 let req = req_builder.build()?;
332 let resp = configuration.client.execute(req).await?;
333
334 let status = resp.status();
335 let content_type = resp
336 .headers()
337 .get("content-type")
338 .and_then(|v| v.to_str().ok())
339 .unwrap_or("application/octet-stream");
340 let content_type = super::ContentType::from(content_type);
341
342 if !status.is_client_error() && !status.is_server_error() {
343 let content = resp.text().await?;
344 match content_type {
345 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
346 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Traces`"))),
347 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::Traces`")))),
348 }
349 } else {
350 let content = resp.text().await?;
351 let entity: Option<TraceListError> = serde_json::from_str(&content).ok();
352 Err(Error::ResponseError(ResponseContent {
353 status,
354 content,
355 entity,
356 }))
357 }
358}