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.
What sets Logfire apart:
- Simple and Powerful: Logfire's dashboard is simple relative to the power it provides, ensuring your entire engineering team will actually use it.
- SQL: Query your data using standard SQL — all the control and (for many) nothing new to learn. Using SQL also means you can query your data with existing BI tools and database querying libraries.
- OpenTelemetry: Logfire is an opinionated wrapper around OpenTelemetry, allowing you to leverage existing tooling, infrastructure, and instrumentation for many common Python packages, and enabling support for virtually any language. We offer full support for all OpenTelemetry signals (traces, metrics and logs).
This repository contains the Rust SDK for instrumenting with Logfire.
See also:
- The SDK documentation on docs.rs for an API reference for this library.
- The Logfire documentation for more information about Logfire in general.
- The Logfire GitHub repository for the source of the documentation, the Python SDK and an issue tracker for general questions about Logfire.
The Logfire server application for recording and displaying data is closed source.
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.
With 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;
use opentelemetry::{KeyValue, metrics::Counter};
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.