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