Skip to main content

langfuse_client_base/apis/
trace_api.rs

1/*
2 * server
3 *
4 * ## 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`
5 *
6 * The version of the OpenAPI document:
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`trace_delete`]
17#[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/// struct for typed errors of method [`trace_delete_multiple`]
29#[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/// struct for typed errors of method [`trace_get`]
41#[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/// struct for typed errors of method [`trace_list`]
53#[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/// Delete a specific trace
65#[bon::builder]
66pub async fn trace_delete(
67    configuration: &configuration::Configuration,
68    trace_id: &str,
69) -> Result<models::DeleteTraceResponse, Error<TraceDeleteError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    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/// Delete multiple traces
119#[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    // add a prefix to parameters to efficiently prevent name collisions
125    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/// **Deprecated:** On Langfuse Cloud, Langfuse v3 is deprecated and this endpoint will be removed on November 16, 2026. In Langfuse v4, read span and trace data via `GET /api/public/v2/observations?fromStartTime=<from>&toStartTime=<to>`. Self-hosted deployments are unaffected by this date; the endpoint becomes unavailable when they upgrade to Langfuse v4. See the [Langfuse v3 to v4 upgrade guide](https://langfuse.com/self-hosting/upgrade/upgrade-guides/upgrade-v3-to-v4).  Get a specific trace
170#[deprecated]
171#[bon::builder]
172pub async fn trace_get(
173    configuration: &configuration::Configuration,
174    trace_id: &str,
175    fields: Option<&str>,
176) -> Result<models::TraceWithFullDetails, Error<TraceGetError>> {
177    // add a prefix to parameters to efficiently prevent name collisions
178    let p_path_trace_id = trace_id;
179    let p_query_fields = fields;
180
181    let uri_str = format!(
182        "{}/api/public/traces/{traceId}",
183        configuration.base_path,
184        traceId = crate::apis::urlencode(p_path_trace_id)
185    );
186    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
187
188    if let Some(ref param_value) = p_query_fields {
189        req_builder = req_builder.query(&[("fields", &param_value.to_string())]);
190    }
191    if let Some(ref user_agent) = configuration.user_agent {
192        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
193    }
194    if let Some(ref auth_conf) = configuration.basic_auth {
195        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
196    };
197
198    let req = req_builder.build()?;
199    let resp = configuration.client.execute(req).await?;
200
201    let status = resp.status();
202    let content_type = resp
203        .headers()
204        .get("content-type")
205        .and_then(|v| v.to_str().ok())
206        .unwrap_or("application/octet-stream");
207    let content_type = super::ContentType::from(content_type);
208
209    if !status.is_client_error() && !status.is_server_error() {
210        let content = resp.text().await?;
211        match content_type {
212            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
213            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TraceWithFullDetails`"))),
214            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`")))),
215        }
216    } else {
217        let content = resp.text().await?;
218        let entity: Option<TraceGetError> = serde_json::from_str(&content).ok();
219        Err(Error::ResponseError(ResponseContent {
220            status,
221            content,
222            entity,
223        }))
224    }
225}
226
227/// **Deprecated:** On Langfuse Cloud, Langfuse v3 is deprecated and this endpoint will be removed on November 16, 2026. In Langfuse v4, read span and trace data via `GET /api/public/v2/observations?fromStartTime=<from>&toStartTime=<to>`. Self-hosted deployments are unaffected by this date; the endpoint becomes unavailable when they upgrade to Langfuse v4. See the [Langfuse v3 to v4 upgrade guide](https://langfuse.com/self-hosting/upgrade/upgrade-guides/upgrade-v3-to-v4).  Get list of traces
228#[deprecated]
229#[bon::builder]
230pub async fn trace_list(
231    configuration: &configuration::Configuration,
232    page: Option<i32>,
233    limit: Option<i32>,
234    user_id: Option<&str>,
235    name: Option<&str>,
236    session_id: Option<&str>,
237    from_timestamp: Option<chrono::DateTime<chrono::FixedOffset>>,
238    to_timestamp: Option<chrono::DateTime<chrono::FixedOffset>>,
239    order_by: Option<&str>,
240    tags: Option<Vec<String>>,
241    version: Option<&str>,
242    release: Option<&str>,
243    environment: Option<Vec<String>>,
244    fields: Option<&str>,
245    filter: Option<&str>,
246) -> Result<models::Traces, Error<TraceListError>> {
247    // add a prefix to parameters to efficiently prevent name collisions
248    let p_query_page = page;
249    let p_query_limit = limit;
250    let p_query_user_id = user_id;
251    let p_query_name = name;
252    let p_query_session_id = session_id;
253    let p_query_from_timestamp = from_timestamp;
254    let p_query_to_timestamp = to_timestamp;
255    let p_query_order_by = order_by;
256    let p_query_tags = tags;
257    let p_query_version = version;
258    let p_query_release = release;
259    let p_query_environment = environment;
260    let p_query_fields = fields;
261    let p_query_filter = filter;
262
263    let uri_str = format!("{}/api/public/traces", configuration.base_path);
264    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
265
266    if let Some(ref param_value) = p_query_page {
267        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
268    }
269    if let Some(ref param_value) = p_query_limit {
270        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
271    }
272    if let Some(ref param_value) = p_query_user_id {
273        req_builder = req_builder.query(&[("userId", &param_value.to_string())]);
274    }
275    if let Some(ref param_value) = p_query_name {
276        req_builder = req_builder.query(&[("name", &param_value.to_string())]);
277    }
278    if let Some(ref param_value) = p_query_session_id {
279        req_builder = req_builder.query(&[("sessionId", &param_value.to_string())]);
280    }
281    if let Some(ref param_value) = p_query_from_timestamp {
282        req_builder = req_builder.query(&[("fromTimestamp", &param_value.to_string())]);
283    }
284    if let Some(ref param_value) = p_query_to_timestamp {
285        req_builder = req_builder.query(&[("toTimestamp", &param_value.to_string())]);
286    }
287    if let Some(ref param_value) = p_query_order_by {
288        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
289    }
290    if let Some(ref param_value) = p_query_tags {
291        req_builder = match "multi" {
292            "multi" => req_builder.query(
293                &param_value
294                    .into_iter()
295                    .map(|p| ("tags".to_owned(), p.to_string()))
296                    .collect::<Vec<(std::string::String, std::string::String)>>(),
297            ),
298            _ => req_builder.query(&[(
299                "tags",
300                &param_value
301                    .into_iter()
302                    .map(|p| p.to_string())
303                    .collect::<Vec<String>>()
304                    .join(",")
305                    .to_string(),
306            )]),
307        };
308    }
309    if let Some(ref param_value) = p_query_version {
310        req_builder = req_builder.query(&[("version", &param_value.to_string())]);
311    }
312    if let Some(ref param_value) = p_query_release {
313        req_builder = req_builder.query(&[("release", &param_value.to_string())]);
314    }
315    if let Some(ref param_value) = p_query_environment {
316        req_builder = match "multi" {
317            "multi" => req_builder.query(
318                &param_value
319                    .into_iter()
320                    .map(|p| ("environment".to_owned(), p.to_string()))
321                    .collect::<Vec<(std::string::String, std::string::String)>>(),
322            ),
323            _ => req_builder.query(&[(
324                "environment",
325                &param_value
326                    .into_iter()
327                    .map(|p| p.to_string())
328                    .collect::<Vec<String>>()
329                    .join(",")
330                    .to_string(),
331            )]),
332        };
333    }
334    if let Some(ref param_value) = p_query_fields {
335        req_builder = req_builder.query(&[("fields", &param_value.to_string())]);
336    }
337    if let Some(ref param_value) = p_query_filter {
338        req_builder = req_builder.query(&[("filter", &param_value.to_string())]);
339    }
340    if let Some(ref user_agent) = configuration.user_agent {
341        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
342    }
343    if let Some(ref auth_conf) = configuration.basic_auth {
344        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
345    };
346
347    let req = req_builder.build()?;
348    let resp = configuration.client.execute(req).await?;
349
350    let status = resp.status();
351    let content_type = resp
352        .headers()
353        .get("content-type")
354        .and_then(|v| v.to_str().ok())
355        .unwrap_or("application/octet-stream");
356    let content_type = super::ContentType::from(content_type);
357
358    if !status.is_client_error() && !status.is_server_error() {
359        let content = resp.text().await?;
360        match content_type {
361            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
362            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Traces`"))),
363            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`")))),
364        }
365    } else {
366        let content = resp.text().await?;
367        let entity: Option<TraceListError> = serde_json::from_str(&content).ok();
368        Err(Error::ResponseError(ResponseContent {
369            status,
370            content,
371            entity,
372        }))
373    }
374}