pub struct Langfuse {
pub prompts: PromptManager,
pub scores: ScoreManager,
pub datasets: DatasetManager,
pub media: MediaManager,
/* private fields */
}Expand description
The main Langfuse client. Holds all managers and the tracing pipeline.
Fields§
§prompts: PromptManagerPrompt management: fetching, caching, and compilation.
scores: ScoreManagerScore creation and batched submission.
datasets: DatasetManagerDataset CRUD operations.
media: MediaManagerMedia upload and fetch.
Implementations§
Source§impl Langfuse
impl Langfuse
Sourcepub fn new(config: LangfuseConfig) -> Result<Self, LangfuseError>
pub fn new(config: LangfuseConfig) -> Result<Self, LangfuseError>
Create a new Langfuse client from config.
Sourcepub fn from_env() -> Result<Self, LangfuseError>
pub fn from_env() -> Result<Self, LangfuseError>
Create from environment variables.
Sourcepub fn init(config: LangfuseConfig) -> Result<&'static Langfuse, LangfuseError>
pub fn init(config: LangfuseConfig) -> Result<&'static Langfuse, LangfuseError>
Initialize the global singleton.
Sourcepub fn init_named(
name: &str,
config: LangfuseConfig,
) -> Result<(), LangfuseError>
pub fn init_named( name: &str, config: LangfuseConfig, ) -> Result<(), LangfuseError>
Initialize a named instance.
Named instances are independent of the global singleton and allow multiple Langfuse clients (e.g. for different projects or environments) to coexist.
Sourcepub fn get_named(name: &str) -> Option<Ref<'static, String, Langfuse>>
pub fn get_named(name: &str) -> Option<Ref<'static, String, Langfuse>>
Get a named instance by name.
Returns None if no instance with the given name has been initialized.
Sourcepub fn try_get_named(
name: &str,
) -> Result<Ref<'static, String, Langfuse>, LangfuseError>
pub fn try_get_named( name: &str, ) -> Result<Ref<'static, String, Langfuse>, LangfuseError>
Try to get a named instance, returning an error if not found.
Sourcepub fn config(&self) -> &LangfuseConfig
pub fn config(&self) -> &LangfuseConfig
Get the config.
Sourcepub async fn auth_check(&self) -> Result<(), LangfuseError>
pub async fn auth_check(&self) -> Result<(), LangfuseError>
Check if authentication is valid by making a test API call.
Sourcepub async fn flush(&self) -> Result<(), LangfuseError>
pub async fn flush(&self) -> Result<(), LangfuseError>
Flush all pending data (scores, traces).
Sourcepub async fn shutdown(&self) -> Result<(), LangfuseError>
pub async fn shutdown(&self) -> Result<(), LangfuseError>
Shut down the client, flushing all pending data.
Sourcepub fn start_span(&self, name: &str) -> LangfuseSpan
pub fn start_span(&self, name: &str) -> LangfuseSpan
Start a new span.
Sourcepub fn start_generation(&self, name: &str) -> LangfuseGeneration
pub fn start_generation(&self, name: &str) -> LangfuseGeneration
Start a new generation.
Sourcepub fn start_span_with_type(
&self,
name: &str,
obs_type: ObservationType,
) -> LangfuseSpan
pub fn start_span_with_type( &self, name: &str, obs_type: ObservationType, ) -> LangfuseSpan
Start a new span with a specific observation type.
Sourcepub fn create_event(&self, name: &str, input: &impl Serialize)
pub fn create_event(&self, name: &str, input: &impl Serialize)
Create a standalone root-level event observation.
Events are zero-duration observations that carry input data. The event span is created and immediately ended.
Sourcepub fn get_trace_url(&self, trace_id: &str) -> String
pub fn get_trace_url(&self, trace_id: &str) -> String
Generate the Langfuse UI URL for a trace.
Sourcepub fn register_tracing(&self)
pub fn register_tracing(&self)
Register the internal tracer provider as the OpenTelemetry global provider.
This must be called once after Langfuse::new for spans created via
LangfuseSpan::start (which uses opentelemetry::global::tracer("langfuse"))
to be exported through the Langfuse OTLP pipeline.
Calling this more than once replaces the previous global provider.