Expand description
§Rust SDK for Pydantic Logfire
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.
The most important API is logfire::configure()
, which is used to set up
integrations with tracing
and log
, as well as exporters for opentelemetry
. Code
instrumented using tracing
and log
will just work once this configuration is in place.
This SDK also offers opinionated functions to instrument code following Logfire’s design principles:
- traces:
logfire::span!()
to create a span with structured data. - logs:
logfire::info!()
,logfire::debug!()
and similar macros to log messages with structured data. - metrics:
logfire::u64_counter()
and similar functions.
See the Logfire documentation for more information about Logfire in general, and the Logfire GitHub repository for the source of that documentation, the Python SDK and an issue tracker for general questions about Logfire.
§Usage
The setup for this SDK is a quick three-step process:
- Add the
logfire
crate to yourCargo.toml
. - Call
logfire::configure()
at the start of your program to set up the SDK. - Run your application with the
LOGFIRE_TOKEN
environment variable set to connect it to the Logfire platform.
This process is demonstrated below. The usage guide contains more detailed information about how to use this SDK to its full potential.
§Getting Started
To use logfire
in your Rust project, add the following to your Cargo.toml
:
[dependencies]
logfire = "0.8.2"
Then, in your Rust code, add a call to logfire::configure()
at the beginning of your program:
fn main() -> Result<(), Box<dyn std::error::Error>> {
let logfire = logfire::configure()
.finish()?;
let _guard = logfire.shutdown_guard();
logfire::info!("Hello world");
// Guard automatically shuts down Logfire when it goes out of scope
Ok(())
}
§Configuration
After adding basic setup as per above, the most two important environment variables are:
LOGFIRE_TOKEN
(required) - the token to send data to the Logfire platformRUST_LOG
(optional) - the level of verbosity to send to the Logfire platform. By default data is captured atTRACE
level so that all data is available for you to analyze in the Logfire platform. This format should match the format used by theenv_logger
crate.
All environment variables supported by the Rust Opentelemetry SDK are also supported by the Logfire SDK.
§Examples
See examples subchapter of this documentation.
Modules§
- config
- Configuration options for the Logfire SDK.
- exporters
- Helper functions to configure mo
- usage
- Usage Guide
Macros§
- debug
- Emit a log at the DEBUG level.
- error
- Emit a log at the ERROR level.
- info
- Emit a log at the INFO level.
- log
- Export a log message at the specified level.
- span
- Create a new
Span
. This macro is a simplified version oftracing::span!
which accepts a smaller set of possible arguments and syntaxes. - trace
- Emit a log at the TRACE level.
- warn
- Emit a log at the WARN level.
Structs§
- Exponential
Histogram - An instrument that records a distribution of values.
- Exponential
Histogram Builder - Configuration for building an exponential Histogram.
- Logfire
- A configured Logfire instance which contains configured
opentelemetry
,tracing
andlog
integrations. - Logfire
Tracing Layer - A
tracing
layer that bridgestracing
spans to OpenTelemetry spans using the Pydantic Logfire tracer. Pydantic Logfire-specific metadata. - Shutdown
Guard - A guard that automatically shuts down Logfire when dropped.
Enums§
- Configure
Error - An error which may arise when configuring Logfire.
- Shutdown
Error - An error which may arise when shutting down Logfire.
Statics§
- EXPONENTIAL_
HISTOGRAMS - A map of histogram name to scale.
Functions§
- configure
- Main entry point to configure logfire.
- f64_
counter - Wrapper for
Meter::f64_counter
using Pydantic Logfire’s global meter. - f64_
exponential_ histogram - Wrapper for
Histogram
using Base2ExponentialHistogram aggregation and Pydantic Logfire’s global meter. - f64_
gauge - Wrapper for
Meter::f64_gauge
using Pydantic Logfire’s global meter. - f64_
histogram - Wrapper for
Meter::f64_histogram
using Pydantic Logfire’s global meter. - f64_
observable_ counter - Wrapper for
Meter::f64_observable_counter
using logfire’s global meter. - f64_
observable_ gauge - Wrapper for
Meter::f64_observable_gauge
using logfire’s global meter. - f64_
observable_ up_ down_ counter - Wrapper for
Meter::f64_observable_up_down_counter
using logfire’s global meter. - f64_
up_ down_ counter - Wrapper for
Meter::f64_up_down_counter
using Pydantic Logfire’s global meter. - i64_
gauge - Wrapper for
Meter::i64_gauge
using Pydantic Logfire’s global meter. - i64_
observable_ gauge - Wrapper for
Meter::i64_observable_gauge
using logfire’s global meter. - i64_
observable_ up_ down_ counter - Wrapper for
Meter::i64_observable_up_down_counter
using logfire’s global meter. - i64_
up_ down_ counter - Wrapper for
Meter::i64_up_down_counter
using Pydantic Logfire’s global meter. - u64_
counter - Wrapper for
Meter::u64_counter
using Pydantic Logfire’s global meter. - u64_
exponential_ histogram - Wrapper for
Histogram
using Base2ExponentialHistogram aggregation and Pydantic Logfire’s global meter. - u64_
gauge - Wrapper for
Meter::u64_gauge
using Pydantic Logfire’s global meter. - u64_
histogram - Wrapper for
Meter::u64_histogram
using Pydantic Logfire’s global meter. - u64_
observable_ counter - Wrapper for
Meter::u64_observable_counter
using logfire’s global meter. - u64_
observable_ gauge - Wrapper for
Meter::u64_observable_gauge
using logfire’s global meter.