Skip to content

pydantic/logfire-rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust SDK for Pydantic Logfire

CI codecov crates.io license MSRV Join Slack

Initial release - feedback wanted!

This is an initial release of the Logfire Rust SDK. We've been using it internally to build Logfire for some time, and it is serving us well. As we're using it ourselves in production, we figured it's ready for everyone else also using Logfire.

We are continually iterating to make this SDK better. We'd love your feedback on all aspects of the SDK and are keen to make the design as idiomatic and performant as possible. There are also many features currently supported by the Python SDK which are not yet supported by this SDK; please open issues to help us prioritize these to close this gap.

In particular, the current coupling to tracing is an open design point. By building on top of tracing we get widest compatibility and a relatively simple SDK, however to make Logfire-specific adjustments we might prefer in future to move tracing to be an optional integration.

From the team behind Pydantic, Logfire is an observability platform built on the same belief as our open source library — that the most powerful tools can be easy to use.

This repository contains the Rust SDK for instrumenting with Logfire.

See also:

The Logfire server application for recording and displaying data is closed source.

Using Logfire's Rust SDK

First set up a Logfire project and create a write token. You'll need to set this token as an environment variable (LOGFIRE_TOKEN) to export to Logfire.

Here's a simple manual tracing (aka logging) example:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let shutdown_handler = logfire::configure()
        .install_panic_handler()
        .send_to_logfire(true)
        .console_mode(logfire::ConsoleMode::Fallback)
        .finish()?;

    logfire::info!("Hello, {name}!", name = "world");

    {
        let _span = logfire::span!(
            "Asking the user their {question}",
            question = "age",
        ).entered();

        println!("When were you born [YYYY-mm-dd]?");
        let mut dob = String::new();
        std::io::stdin().read_line(&mut dob)?;

        logfire::debug!("dob={dob}", dob = dob.trim().to_owned());
    }

    shutdown_handler.shutdown()?;
    Ok(())
}

Integration

Logfire's Rust SDK is currently built directly upon tracing and opentelemetry.

This means that anything instrumented using tracing will just work with logfire (however this SDK's macros contain some additional customizations on top of tracing for best support directly on the Logfire platform).

There is also an integration with log, so anything using log will also be captured by Logfire.

Contributing

We'd love anyone interested to contribute to the Logfire SDK!

Please send us all your feedback and ideas about the current design and functionality of this SDK. Code contributions are also very welcome!

Reporting a Security Vulnerability

See our security policy.