Expand description
§Firebase Performance
This module contains the Rust port of the Firebase Performance Monitoring SDK. The implementation now exposes the component through the shared container, provides configurable runtime toggles, implements manual trace plus HTTP instrumentation primitives, runs WASM-friendly auto instrumentation, and ships a cross-platform trace queue with an async transport worker so the data path mirrors the JS SDK end-to-end.
Porting status: 70% [#######..] (details)
§Quick Start Example
use std::time::Duration;
use firebase_rs_sdk::app::initialize_app;
use firebase_rs_sdk::app::{FirebaseAppSettings, FirebaseOptions};
use firebase_rs_sdk::performance::{get_performance, HttpMethod, TransportOptions};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let options = FirebaseOptions {
project_id: Some("demo-project".into()),
..Default::default()
};
let settings = FirebaseAppSettings {
name: Some("demo-app".into()),
..Default::default()
};
let app = initialize_app(options, Some(settings)).await?;
let performance = get_performance(Some(app.clone())).await?;
performance.configure_transport(TransportOptions {
endpoint: Some("https://firebaselogging.googleapis.com/v0cc/log?format=json_proto3".into()),
api_key: app.options().api_key.clone(),
flush_interval: Some(Duration::from_secs(5)),
max_batch_size: Some(25),
});
let mut trace = performance.new_trace("page_load")?;
trace.start()?;
trace.put_metric("items_rendered", 5)?;
tokio::time::sleep(Duration::from_millis(25)).await;
let trace_data = trace.stop().await?;
println!(
"trace '{}' completed in {:?} with metrics {:?}",
trace_data.name, trace_data.duration, trace_data.metrics
);
let mut request = performance
.new_network_request("https://example.com/api", HttpMethod::Get)?;
request.start()?;
// ... perform the actual HTTP call ...
let http_metrics = request.stop().await?;
println!(
"network trace '{}' {:?} us",
http_metrics.url, http_metrics.time_to_request_completed_us
);
Ok(())
}§References to the Firebase JS SDK
- QuickStart: https://firebase.google.com/docs/perf-mon/get-started-web
- API: https://firebase.google.com/docs/reference/js/performance.md#performance_package
- Github Repo - Module: https://github.com/firebase/firebase-js-sdk/tree/main/packages/performance
- Github Repo - API: https://github.com/firebase/firebase-js-sdk/tree/main/packages/firebase/performance
Structs§
- Network
Request Record - Captured HTTP request metadata that mirrors the payload sent by the JS SDK when batching network traces to the backend.
- Network
Trace Handle - Builder for manual network request instrumentation. Mirrors the JS
NetworkRequestTracehelper and records timing plus payload metadata. - Performance
- Firebase Performance Monitoring entry point tied to a
FirebaseApp. - Performance
Error - Performance
Runtime Settings - Resolved runtime settings that reflect the effective data collection and
instrumentation flags for a
Performanceinstance. - Performance
Settings - User provided configuration toggles mirroring the JavaScript SDK’s
PerformanceSettings. - Performance
Trace - Immutable snapshot of a recorded trace with timing, metrics, and attributes.
- Trace
Handle - Builder for manual traces (
Tracein the JS SDK). - Trace
Record Options - Optional bundle of metrics and attributes passed into
TraceHandle::record. - Transport
Controller - Transport
Options - Transport configuration surface for batch uploads.
Enums§
- Http
Method - HTTP method enum reused by
NetworkTraceHandle. Represents the HTTP verb associated with aNetworkTraceHandle. - Performance
Error Code
Constants§
- MAX_
ATTRIBUTE_ NAME_ LENGTH - MAX_
ATTRIBUTE_ VALUE_ LENGTH - MAX_
METRIC_ NAME_ LENGTH - OOB_
TRACE_ PAGE_ LOAD_ PREFIX - PERFORMANCE_
COMPONENT_ NAME - RESERVED_
ATTRIBUTE_ PREFIXES - RESERVED_
METRIC_ PREFIX
Functions§
- get_
performance - Resolves (or lazily creates) the
Performanceinstance for the provided app. WhenappisNone, the default app is used. - initialize_
performance - Initializes the performance component with explicit settings (akin to the
JS SDK’s
initializePerformance). Subsequent calls with a different configuration will fail. - internal_
error - invalid_
argument - is_
supported - Returns
truewhen performance monitoring is expected to work on the current platform (matches the checks performed in the JS SDK). - register_
performance_ component - Registers the performance component in the shared container (normally invoked automatically).