Skip to main content

bitwarden_wasm_internal/
flight_recorder.rs

1//! WASM bindings for the Flight Recorder.
2
3use bitwarden_logging::{FlightRecorderEvent, flight_recorder_count, read_flight_recorder};
4use wasm_bindgen::prelude::*;
5
6/// WASM client for reading Flight Recorder logs.
7///
8/// The underlying buffer is global (initialized in [`init_sdk`](crate::init_sdk)),
9/// so this client is a stateless handle for WASM access.
10#[wasm_bindgen]
11pub struct FlightRecorderClient;
12
13#[wasm_bindgen]
14impl FlightRecorderClient {
15    /// Create a new `FlightRecorderClient`.
16    #[wasm_bindgen(constructor)]
17    pub fn new() -> Self {
18        Self
19    }
20
21    /// Read all events currently in the Flight Recorder buffer.
22    pub fn read(&self) -> Vec<FlightRecorderEvent> {
23        read_flight_recorder()
24    }
25
26    /// Get the current event count without reading event contents.
27    pub fn count(&self) -> usize {
28        flight_recorder_count()
29    }
30}
31
32impl Default for FlightRecorderClient {
33    fn default() -> Self {
34        Self::new()
35    }
36}