langfuse_client/apis/
trace_api.rs

1/*
2 * langfuse
3 *
4 * ## 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 - Postman collection: https://cloud.langfuse.com/generated/postman/collection.json
5 *
6 * The version of the OpenAPI document: 
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`trace_delete`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum TraceDeleteError {
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/// struct for typed errors of method [`trace_delete_multiple`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum TraceDeleteMultipleError {
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/// struct for typed errors of method [`trace_get`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum TraceGetError {
46    Status400(serde_json::Value),
47    Status401(serde_json::Value),
48    Status403(serde_json::Value),
49    Status404(serde_json::Value),
50    Status405(serde_json::Value),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`trace_list`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum TraceListError {
58    Status400(serde_json::Value),
59    Status401(serde_json::Value),
60    Status403(serde_json::Value),
61    Status404(serde_json::Value),
62    Status405(serde_json::Value),
63    UnknownValue(serde_json::Value),
64}
65
66
67/// Delete a specific trace
68pub async fn trace_delete(configuration: &configuration::Configuration, trace_id: &str) -> Result<models::DeleteTraceResponse, Error<TraceDeleteError>> {
69    // add a prefix to parameters to efficiently prevent name collisions
70    let p_trace_id = trace_id;
71
72    let uri_str = format!("{}/api/public/traces/{traceId}", configuration.base_path, traceId=crate::apis::urlencode(p_trace_id));
73    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
74
75    if let Some(ref user_agent) = configuration.user_agent {
76        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77    }
78    if let Some(ref auth_conf) = configuration.basic_auth {
79        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
80    };
81
82    let req = req_builder.build()?;
83    let resp = configuration.client.execute(req).await?;
84
85    let status = resp.status();
86    let content_type = resp
87        .headers()
88        .get("content-type")
89        .and_then(|v| v.to_str().ok())
90        .unwrap_or("application/octet-stream");
91    let content_type = super::ContentType::from(content_type);
92
93    if !status.is_client_error() && !status.is_server_error() {
94        let content = resp.text().await?;
95        match content_type {
96            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
97            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteTraceResponse`"))),
98            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`")))),
99        }
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<TraceDeleteError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent { status, content, entity }))
104    }
105}
106
107/// Delete multiple traces
108pub async fn trace_delete_multiple(configuration: &configuration::Configuration, trace_delete_multiple_request: models::TraceDeleteMultipleRequest) -> Result<models::DeleteTraceResponse, Error<TraceDeleteMultipleError>> {
109    // add a prefix to parameters to efficiently prevent name collisions
110    let p_trace_delete_multiple_request = trace_delete_multiple_request;
111
112    let uri_str = format!("{}/api/public/traces", configuration.base_path);
113    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
114
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118    if let Some(ref auth_conf) = configuration.basic_auth {
119        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
120    };
121    req_builder = req_builder.json(&p_trace_delete_multiple_request);
122
123    let req = req_builder.build()?;
124    let resp = configuration.client.execute(req).await?;
125
126    let status = resp.status();
127    let content_type = resp
128        .headers()
129        .get("content-type")
130        .and_then(|v| v.to_str().ok())
131        .unwrap_or("application/octet-stream");
132    let content_type = super::ContentType::from(content_type);
133
134    if !status.is_client_error() && !status.is_server_error() {
135        let content = resp.text().await?;
136        match content_type {
137            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
138            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteTraceResponse`"))),
139            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`")))),
140        }
141    } else {
142        let content = resp.text().await?;
143        let entity: Option<TraceDeleteMultipleError> = serde_json::from_str(&content).ok();
144        Err(Error::ResponseError(ResponseContent { status, content, entity }))
145    }
146}
147
148/// Get a specific trace
149pub async fn trace_get(configuration: &configuration::Configuration, trace_id: &str) -> Result<models::TraceWithFullDetails, Error<TraceGetError>> {
150    // add a prefix to parameters to efficiently prevent name collisions
151    let p_trace_id = trace_id;
152
153    let uri_str = format!("{}/api/public/traces/{traceId}", configuration.base_path, traceId=crate::apis::urlencode(p_trace_id));
154    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
155
156    if let Some(ref user_agent) = configuration.user_agent {
157        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
158    }
159    if let Some(ref auth_conf) = configuration.basic_auth {
160        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
161    };
162
163    let req = req_builder.build()?;
164    let resp = configuration.client.execute(req).await?;
165
166    let status = resp.status();
167    let content_type = resp
168        .headers()
169        .get("content-type")
170        .and_then(|v| v.to_str().ok())
171        .unwrap_or("application/octet-stream");
172    let content_type = super::ContentType::from(content_type);
173
174    if !status.is_client_error() && !status.is_server_error() {
175        let content = resp.text().await?;
176        match content_type {
177            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
178            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TraceWithFullDetails`"))),
179            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`")))),
180        }
181    } else {
182        let content = resp.text().await?;
183        let entity: Option<TraceGetError> = serde_json::from_str(&content).ok();
184        Err(Error::ResponseError(ResponseContent { status, content, entity }))
185    }
186}
187
188/// Get list of traces
189pub async fn trace_list(configuration: &configuration::Configuration, page: Option<i32>, limit: Option<i32>, user_id: Option<&str>, name: Option<&str>, session_id: Option<&str>, from_timestamp: Option<String>, to_timestamp: Option<String>, order_by: Option<&str>, tags: Option<Vec<String>>, version: Option<&str>, release: Option<&str>, environment: Option<Vec<String>>) -> Result<models::Traces, Error<TraceListError>> {
190    // add a prefix to parameters to efficiently prevent name collisions
191    let p_page = page;
192    let p_limit = limit;
193    let p_user_id = user_id;
194    let p_name = name;
195    let p_session_id = session_id;
196    let p_from_timestamp = from_timestamp;
197    let p_to_timestamp = to_timestamp;
198    let p_order_by = order_by;
199    let p_tags = tags;
200    let p_version = version;
201    let p_release = release;
202    let p_environment = environment;
203
204    let uri_str = format!("{}/api/public/traces", configuration.base_path);
205    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
206
207    if let Some(ref param_value) = p_page {
208        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
209    }
210    if let Some(ref param_value) = p_limit {
211        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
212    }
213    if let Some(ref param_value) = p_user_id {
214        req_builder = req_builder.query(&[("userId", &param_value.to_string())]);
215    }
216    if let Some(ref param_value) = p_name {
217        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
218    }
219    if let Some(ref param_value) = p_session_id {
220        req_builder = req_builder.query(&[("sessionId", &param_value.to_string())]);
221    }
222    if let Some(ref param_value) = p_from_timestamp {
223        req_builder = req_builder.query(&[("fromTimestamp", &param_value.to_string())]);
224    }
225    if let Some(ref param_value) = p_to_timestamp {
226        req_builder = req_builder.query(&[("toTimestamp", &param_value.to_string())]);
227    }
228    if let Some(ref param_value) = p_order_by {
229        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
230    }
231    if let Some(ref param_value) = p_tags {
232        req_builder = match "multi" {
233            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
234            _ => req_builder.query(&[("tags", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
235        };
236    }
237    if let Some(ref param_value) = p_version {
238        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
239    }
240    if let Some(ref param_value) = p_release {
241        req_builder = req_builder.query(&[("release", &param_value.to_string())]);
242    }
243    if let Some(ref param_value) = p_environment {
244        req_builder = match "multi" {
245            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("environment".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
246            _ => req_builder.query(&[("environment", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
247        };
248    }
249    if let Some(ref user_agent) = configuration.user_agent {
250        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
251    }
252    if let Some(ref auth_conf) = configuration.basic_auth {
253        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
254    };
255
256    let req = req_builder.build()?;
257    let resp = configuration.client.execute(req).await?;
258
259    let status = resp.status();
260    let content_type = resp
261        .headers()
262        .get("content-type")
263        .and_then(|v| v.to_str().ok())
264        .unwrap_or("application/octet-stream");
265    let content_type = super::ContentType::from(content_type);
266
267    if !status.is_client_error() && !status.is_server_error() {
268        let content = resp.text().await?;
269        match content_type {
270            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
271            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Traces`"))),
272            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`")))),
273        }
274    } else {
275        let content = resp.text().await?;
276        let entity: Option<TraceListError> = serde_json::from_str(&content).ok();
277        Err(Error::ResponseError(ResponseContent { status, content, entity }))
278    }
279}
280