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:
logfire::info!()
,logfire::debug!()
and similar macros to log messages with structured data.logfire::span!()
to create a span with structured data.logfire::u64_counter()
and similar functions to create metrics.
See also:
- The integrations section below for more information on the relationship of this SDK to other libraries.
- The examples subchapter of this documentation.
- 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.
§Usage
See below for a quick summary of how to use this SDK. 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.7.1"
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 shutdown_handler = logfire::configure()
.install_panic_handler()
.finish()?;
logfire::info!("Hello world");
shutdown_handler.shutdown()?;
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§
- Logfire
Config Builder - Builder for logfire configuration, returned from
logfire::configure()
. - Logfire
Tracing Layer - A
tracing
layer that bridgestracing
spans to OpenTelemetry spans using the Pydantic Logfire tracer. Pydantic Logfire-specific metadata. - Shutdown
Handler - A handler to shutdown the Logfire configuration.
Enums§
- Configure
Error - An error which may arise when configuring Logfire.
Functions§
- configure
- Main entry point to configure logfire.
- f64_
counter - Wrapper for
Meter::f64_counter
using 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_
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.