| Crates.io | logfire |
| lib.rs | logfire |
| version | 0.8.2 |
| created_at | 2023-09-02 13:43:58.94486+00 |
| updated_at | 2025-09-10 00:29:45.216863+00 |
| description | Rust SDK for Pydantic Logfire |
| homepage | https://github.com/pydantic/logfire-rust |
| repository | https://github.com/pydantic/logfire-rust |
| max_upload_size | |
| id | 961675 |
| size | 569,510 |
From the team behind Pydantic Validation, 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.
What sets Logfire apart:
This repository contains the Rust SDK for instrumenting with Logfire.
See also:
The Logfire server application for recording and displaying data is closed source.
First set up a Logfire project. You will then configure the SDK to send to Logfire by:
LOGFIRE_TOKEN), orWith a logfire project set up, start by adding the logfire crate to your Cargo.toml:
[dependencies]
logfire = "0.6"
Then, you can use the SDK to instrument the code. Here's a simple example which counts the size of files in the current directory, creating spans for the full operation and each file read:
use std::fs;
use std::sync::LazyLock;
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
fn main() -> Result<()> {
let shutdown_handler = logfire::configure().install_panic_handler().finish()?;
let mut total_size = 0u64;
let cwd = std::env::current_dir()?;
logfire::span!("counting size of {cwd}", cwd = cwd.display().to_string()).in_scope(|| {
let entries = fs::read_dir(&cwd)?;
for entry in entries {
let entry = entry?;
let path = entry.path();
let _span = logfire::span!(
"reading {path}",
path = path
.strip_prefix(&cwd)
.unwrap_or(&path)
.display()
.to_string()
)
.entered();
let metadata = entry.metadata()?;
if metadata.is_file() {
total_size += metadata.len();
}
}
Result::Ok(())
})?;
logfire::info!(
"total size of {cwd} is {size} bytes",
cwd = cwd.display().to_string(),
size = total_size as i64
);
shutdown_handler.shutdown()?;
Ok(())
}
(Read the Logfire concepts documentation for additional detail on spans, events, and further Logfire concepts.)
See additional examples in the examples directory:
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.
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!
See our security policy.