Module performance

Module performance 

Source
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

Structs§

NetworkRequestRecord
Captured HTTP request metadata that mirrors the payload sent by the JS SDK when batching network traces to the backend.
NetworkTraceHandle
Builder for manual network request instrumentation. Mirrors the JS NetworkRequestTrace helper and records timing plus payload metadata.
Performance
Firebase Performance Monitoring entry point tied to a FirebaseApp.
PerformanceError
PerformanceRuntimeSettings
Resolved runtime settings that reflect the effective data collection and instrumentation flags for a Performance instance.
PerformanceSettings
User provided configuration toggles mirroring the JavaScript SDK’s PerformanceSettings.
PerformanceTrace
Immutable snapshot of a recorded trace with timing, metrics, and attributes.
TraceHandle
Builder for manual traces (Trace in the JS SDK).
TraceRecordOptions
Optional bundle of metrics and attributes passed into TraceHandle::record.
TransportController
TransportOptions
Transport configuration surface for batch uploads.

Enums§

HttpMethod
HTTP method enum reused by NetworkTraceHandle. Represents the HTTP verb associated with a NetworkTraceHandle.
PerformanceErrorCode

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 Performance instance for the provided app. When app is None, 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 true when 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).

Type Aliases§

PerformanceResult