pub struct TelemetryCollector { /* private fields */ }Expand description
Main telemetry collector for Juncture graph execution.
Creates traces and observations, applies capture configuration, and submits them to the batch writer for async persistence.
§Examples
use juncture_telemetry::{TelemetryCollector, SqliteStore};
use std::sync::Arc;
let store = Arc::new(SqliteStore::new("telemetry.db").await?);
let collector = TelemetryCollector::new(store);
let trace = collector.begin_trace("my_graph", Some("thread-1"));
let obs = collector.begin_llm_call(trace.id, "claude-sonnet-4-20250514");
// ... execute LLM call ...
collector.end_llm_call(obs.id, Some(response), usage, cost).await;
collector.end_trace(trace.id, Some(output), total_cost, total_tokens).await;Implementations§
Source§impl TelemetryCollector
impl TelemetryCollector
Sourcepub fn new(store: Arc<dyn TraceStore>) -> Self
pub fn new(store: Arc<dyn TraceStore>) -> Self
Create a new collector with default capture configuration.
Sourcepub fn with_capture_config(
store: Arc<dyn TraceStore>,
config: CaptureConfig,
) -> Self
pub fn with_capture_config( store: Arc<dyn TraceStore>, config: CaptureConfig, ) -> Self
Create a new collector with custom capture configuration.
Sourcepub fn with_langfuse(
store: Arc<dyn TraceStore>,
config: CaptureConfig,
langfuse_config: LangfuseConfig,
) -> Self
pub fn with_langfuse( store: Arc<dyn TraceStore>, config: CaptureConfig, langfuse_config: LangfuseConfig, ) -> Self
Create a new collector with Langfuse cloud export enabled.
When configured, flush() and shutdown() automatically export
traces and observations to Langfuse cloud alongside local storage.
Sourcepub fn capture_config(&self) -> &CaptureConfig
pub fn capture_config(&self) -> &CaptureConfig
Get the capture configuration.
Sourcepub async fn begin_trace(
&self,
graph_name: impl Into<String>,
session_id: Option<String>,
) -> Result<Trace, StoreError>
pub async fn begin_trace( &self, graph_name: impl Into<String>, session_id: Option<String>, ) -> Result<Trace, StoreError>
Begin a new trace for a graph invocation.
The trace is immediately submitted to the buffer so that observations can reference it without FK constraint violations.
§Errors
Returns StoreError::Storage if the submission fails.
Sourcepub async fn end_trace(
&self,
trace: Trace,
output: Option<Value>,
total_cost: Option<f64>,
total_tokens: Option<u64>,
) -> Result<(), StoreError>
pub async fn end_trace( &self, trace: Trace, output: Option<Value>, total_cost: Option<f64>, total_tokens: Option<u64>, ) -> Result<(), StoreError>
End a trace and submit the completed version for async writing.
§Errors
Returns StoreError::Storage if the submission fails.
Sourcepub async fn track_session(
&self,
thread_id: impl Into<String>,
user_id: Option<String>,
) -> Result<(), StoreError>
pub async fn track_session( &self, thread_id: impl Into<String>, user_id: Option<String>, ) -> Result<(), StoreError>
Sourcepub fn begin_llm_call(
&self,
trace_id: Id,
parent_id: Option<Id>,
model: impl Into<String>,
prompt: Option<&Value>,
) -> Observation
pub fn begin_llm_call( &self, trace_id: Id, parent_id: Option<Id>, model: impl Into<String>, prompt: Option<&Value>, ) -> Observation
Begin an LLM call observation.
Sourcepub async fn end_llm_call(
&self,
obs: Observation,
response: Option<&str>,
usage: Option<TokenUsage>,
cost: Option<f64>,
) -> Result<(), StoreError>
pub async fn end_llm_call( &self, obs: Observation, response: Option<&str>, usage: Option<TokenUsage>, cost: Option<f64>, ) -> Result<(), StoreError>
End an LLM call observation and submit it.
§Errors
Returns StoreError::Storage if the submission fails.
Sourcepub fn begin_tool_call(
&self,
trace_id: Id,
parent_id: Option<Id>,
tool_name: impl Into<String>,
input: Option<&Value>,
) -> Observation
pub fn begin_tool_call( &self, trace_id: Id, parent_id: Option<Id>, tool_name: impl Into<String>, input: Option<&Value>, ) -> Observation
Begin a tool call observation.
Sourcepub async fn end_tool_call(
&self,
obs: Observation,
output: Option<Value>,
) -> Result<(), StoreError>
pub async fn end_tool_call( &self, obs: Observation, output: Option<Value>, ) -> Result<(), StoreError>
End a tool call observation and submit it.
§Errors
Returns StoreError::Storage if the submission fails.
Sourcepub fn begin_span(
&self,
trace_id: Id,
parent_id: Option<Id>,
name: impl Into<String>,
) -> Observation
pub fn begin_span( &self, trace_id: Id, parent_id: Option<Id>, name: impl Into<String>, ) -> Observation
Begin a generic span observation.
Sourcepub async fn end_span(
&self,
obs: Observation,
output: Option<Value>,
) -> Result<(), StoreError>
pub async fn end_span( &self, obs: Observation, output: Option<Value>, ) -> Result<(), StoreError>
Sourcepub async fn fail_span(
&self,
obs: Observation,
error: impl Into<String>,
) -> Result<(), StoreError>
pub async fn fail_span( &self, obs: Observation, error: impl Into<String>, ) -> Result<(), StoreError>
Trait Implementations§
Source§impl Clone for TelemetryCollector
impl Clone for TelemetryCollector
Source§fn clone(&self) -> TelemetryCollector
fn clone(&self) -> TelemetryCollector
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for TelemetryCollector
impl !UnwindSafe for TelemetryCollector
impl Freeze for TelemetryCollector
impl Send for TelemetryCollector
impl Sync for TelemetryCollector
impl Unpin for TelemetryCollector
impl UnsafeUnpin for TelemetryCollector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more