Skip to main content

Langfuse

Struct Langfuse 

Source
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: PromptManager

Prompt management: fetching, caching, and compilation.

§scores: ScoreManager

Score creation and batched submission.

§datasets: DatasetManager

Dataset CRUD operations.

§media: MediaManager

Media upload and fetch.

Implementations§

Source§

impl Langfuse

Source

pub fn new(config: LangfuseConfig) -> Result<Self, LangfuseError>

Create a new Langfuse client from config.

Source

pub fn from_env() -> Result<Self, LangfuseError>

Create from environment variables.

Source

pub fn init(config: LangfuseConfig) -> Result<&'static Langfuse, LangfuseError>

Initialize the global singleton.

Source

pub fn get() -> &'static Langfuse

Get the global singleton (panics if not initialized).

Source

pub fn try_get() -> Option<&'static Langfuse>

Try to get the global singleton.

Source

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.

Source

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.

Source

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.

Source

pub fn config(&self) -> &LangfuseConfig

Get the config.

Source

pub async fn auth_check(&self) -> Result<(), LangfuseError>

Check if authentication is valid by making a test API call.

Source

pub async fn flush(&self) -> Result<(), LangfuseError>

Flush all pending data (scores, traces).

Source

pub async fn shutdown(&self) -> Result<(), LangfuseError>

Shut down the client, flushing all pending data.

Source

pub fn start_span(&self, name: &str) -> LangfuseSpan

Start a new span.

Source

pub fn start_generation(&self, name: &str) -> LangfuseGeneration

Start a new generation.

Source

pub fn start_span_with_type( &self, name: &str, obs_type: ObservationType, ) -> LangfuseSpan

Start a new span with a specific observation type.

Source

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.

Source

pub fn get_trace_url(&self, trace_id: &str) -> String

Generate the Langfuse UI URL for a trace.

Source

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.

Trait Implementations§

Source§

impl Debug for Langfuse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Langfuse

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more