Skip to main content

observe

Attribute Macro observe 

Source
#[observe]
Expand description

Instrument a function with Langfuse tracing.

§Attributes

  • #[observe] — default: span name = function name, type = span
  • #[observe(name = "custom")] — override span name
  • #[observe(as_type = "generation")] — use generation instead of span
  • #[observe(capture_input = false)] — skip serializing input args
  • #[observe(capture_output = false)] — skip serializing output
  • #[observe(transform_to_string = "my_fn")] — custom transform for stream/iterator output

§Stream / Iterator Support

If the return type contains Stream, the result is automatically wrapped in ObservingStream which collects items and finalizes the span when the stream completes.

Similarly, if the return type contains Iterator, the result is wrapped in ObservingIterator.

§Example

use langfuse::observe;

#[observe]
async fn my_func(query: &str) -> String {
    format!("result for {}", query)
}