Skip to main content

Crate bitwarden_logging

Crate bitwarden_logging 

Source
Expand description

§Bitwarden Logging

Flight Recorder infrastructure for capturing and exporting diagnostic logs.

Internal crate for the bitwarden crate. Do not use.

§Working With FlightRecorder

The Flight Recorder captures tracing events into a global circular buffer so they can be exported for diagnostics without requiring the caller to hold a direct reference to the buffer.

§Initialization

Call init_flight_recorder during SDK startup and add the returned layer to your tracing subscriber:

use bitwarden_logging::{init_flight_recorder, FlightRecorderConfig};
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _};

let flight_recorder_layer = init_flight_recorder(FlightRecorderConfig::default());

tracing_subscriber::registry()
    .with(flight_recorder_layer)
    .init();

The default configuration retains 1 000 events at DEBUG level. Use FlightRecorderConfig::new for custom settings.

§Reading events

Once initialized, events can be read from anywhere in the process:

use bitwarden_logging::{read_flight_recorder, flight_recorder_count};

let count = flight_recorder_count();
let events = read_flight_recorder();

Both functions return safe defaults (0 / empty Vec) if the recorder has not been initialized.

§WASM usage

In bitwarden-wasm-internal, the recorder is automatically initialized by init_sdk(). TypeScript consumers access it through FlightRecorderClient:

import { FlightRecorderClient } from "@aspect/bitwarden-wasm-internal";

const recorder = new FlightRecorderClient();
const count = recorder.count();
const events = recorder.read();

Each FlightRecorderEvent contains timestamp, level, target, message, and fields.

Modules§

circular_buffer 🔒
Thread-safe circular buffer implementation.
config 🔒
Configuration for the Flight Recorder.
event 🔒
Flight Recorder event definitions.
global 🔒
Global Flight Recorder buffer and convenience accessors.
layer 🔒
Tracing subscriber layer for Flight Recorder.
visitor 🔒
Visitor for extracting fields from tracing events.

Structs§

CircularBuffer
A thread-safe circular buffer with FIFO eviction.
FlightRecorderConfig
Configuration for the Flight Recorder system.
FlightRecorderEvent
A single log event captured by the Flight Recorder.
FlightRecorderLayer
A tracing subscriber layer that captures log events into a circular buffer.
MessageVisitor
Extracts the message and structured fields from a tracing event.

Functions§

flight_recorder_count
Get the current event count without reading event contents.
get_flight_recorder_buffer
Get the global Flight Recorder buffer.
init_flight_recorder
Initialize the global Flight Recorder.
read_flight_recorder
Read all events from the global Flight Recorder buffer.