pub struct ScoreManager { /* private fields */ }Expand description
Manages score creation and batched submission to the Langfuse API.
Scores are buffered in a BatchQueue and flushed to the ingestion
endpoint either when the buffer reaches flush_at or on explicit
flush / shutdown.
A background task periodically flushes buffered scores at the configured
flush_interval.
Implementations§
Source§impl ScoreManager
impl ScoreManager
Sourcepub fn new(config: &LangfuseConfig) -> Self
pub fn new(config: &LangfuseConfig) -> Self
Create a new ScoreManager from the given configuration.
Spawns a background task that auto-flushes buffered scores at the
configured flush_interval.
Sourcepub fn score(&self, body: ScoreBody)
pub fn score(&self, body: ScoreBody)
Create a score and add it to the batch queue.
If the queue reaches flush_at, a flush would be triggered
(currently buffered for explicit flush).
Sourcepub fn score_observation(
&self,
trace_id: &str,
observation_id: &str,
name: &str,
value: ScoreValue,
)
pub fn score_observation( &self, trace_id: &str, observation_id: &str, name: &str, value: ScoreValue, )
Score a specific observation within a trace.
Sourcepub fn score_observation_with(&self, body: ScoreBody)
pub fn score_observation_with(&self, body: ScoreBody)
Score a specific observation with a full ScoreBody.
This is the rich variant of score_observation
that accepts a pre-built body with optional comment, metadata, etc.
Sourcepub fn score_trace(&self, trace_id: &str, name: &str, value: ScoreValue)
pub fn score_trace(&self, trace_id: &str, name: &str, value: ScoreValue)
Score a trace.
Sourcepub async fn flush(&self) -> Result<(), LangfuseError>
pub async fn flush(&self) -> Result<(), LangfuseError>
Flush all buffered scores to the Langfuse ingestion API.
Drains the buffer and POSTs a batch of score-create events.
Returns Ok(()) immediately if the buffer is empty.
Sourcepub async fn shutdown(&self) -> Result<(), LangfuseError>
pub async fn shutdown(&self) -> Result<(), LangfuseError>
Flush all buffered scores and shut down the background task.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of scores currently buffered.