Crate logfire

Source
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:

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 platform
  • RUST_LOG (optional) - the level of verbosity to send to the Logfire platform. By default data is captured at TRACE level so that all data is available for you to analyze in the Logfire platform. This format should match the format used by the env_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 of tracing::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§

LogfireConfigBuilder
Builder for logfire configuration, returned from logfire::configure().
LogfireTracingLayer
A tracing layer that bridges tracing spans to OpenTelemetry spans using the Pydantic Logfire tracer. Pydantic Logfire-specific metadata.
ShutdownHandler
A handler to shutdown the Logfire configuration.

Enums§

ConfigureError
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.