Crate logfire

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

  1. Add the logfire crate to your Cargo.toml.
  2. Call logfire::configure() at the start of your program to set up the SDK.
  3. 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 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§

ExponentialHistogram
An instrument that records a distribution of values.
ExponentialHistogramBuilder
Configuration for building an exponential Histogram.
Logfire
A configured Logfire instance which contains configured opentelemetry, tracing and log integrations.
LogfireTracingLayer
A tracing layer that bridges tracing spans to OpenTelemetry spans using the Pydantic Logfire tracer. Pydantic Logfire-specific metadata.
ShutdownGuard
A guard that automatically shuts down Logfire when dropped.

Enums§

ConfigureError
An error which may arise when configuring Logfire.
ShutdownError
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.