Skip to main content

UsageReporter

Trait UsageReporter 

Source
pub trait UsageReporter: 'static {
    // Required methods
    fn record(&self, event: &Event<'_>);
    fn adapter_name(&self) -> &'static str;
    fn endpoint(&self) -> &str;

    // Provided methods
    fn flush(&self) -> Result<(), TelemetryError> { ... }
    fn discard_pending(&self) -> Result<(), TelemetryError> { ... }
    fn erase_remote_data(&self) -> Result<(), TelemetryError> { ... }
    fn fetch_remote_data(&self) -> Result<RemoteDataExport, TelemetryError> { ... }
    fn install_id(&self) -> Option<&str> { ... }
    fn supported_scopes(&self) -> ConsentScope { ... }
}
Expand description

The observability sink. Implemented by adapter crates (teksilo-analytics-plausible, teksilo-analytics-posthog, etc.) and by teksilo-telemetry::DynamicReporter (which forwards to whichever concrete adapter is currently active).

Object-safe — registered into the app-state registry as Rc<dyn UsageReporter> and looked up by trait-object pointer.

Single-threaded. Teksilo is single-threaded by design (the arena, Signal<T>, ListModel<T> are all Rc<RefCell<>>-shaped). Adapters that need a worker thread for HTTP transport bridge internally with channels and own a separate Send-able state; the trait surface itself stays on the UI thread.

Implementations MUST gate emission on consent state internally. The dispatch tap calls record unconditionally; the reporter drops the event when consent is not Granted.

Required Methods§

Source

fn record(&self, event: &Event<'_>)

Invoked synchronously from any thread. MUST NOT block the caller (queue and return). Drops events when consent is not Granted. Errors are buffered internally — there is no return value because the caller cannot meaningfully react.

Source

fn adapter_name(&self) -> &'static str

"plausible", "posthog", "otlp", "stub". Shown in the widget’s “what gets sent” tab.

Source

fn endpoint(&self) -> &str

Endpoint URL displayed verbatim in the consent widget.

Provided Methods§

Source

fn flush(&self) -> Result<(), TelemetryError>

Best-effort drain of the on-disk queue. Called on graceful exit. Not called on consent revocation — see Self::discard_pending.

Source

fn discard_pending(&self) -> Result<(), TelemetryError>

Drop the queue without sending. Called when consent is revoked, when the mode is switched, or when the user clicks “Erase my data”. Once consent is Denied or Unknown, the buffered events are no longer permitted to leave the device.

Source

fn erase_remote_data(&self) -> Result<(), TelemetryError>

GDPR Art. 17. Pseudonymous mode: send DELETE keyed by install_id; clear the local queue. Anonymous mode: returns TelemetryError::ErasureUnsupported so the widget can hide the button.

Source

fn fetch_remote_data(&self) -> Result<RemoteDataExport, TelemetryError>

GDPR Art. 15 + 20. Pseudonymous mode: fetch all server-side events for this install_id as a RemoteDataExport. Anonymous mode: returns TelemetryError::FetchUnsupported.

Source

fn install_id(&self) -> Option<&str>

Some(uuid) in pseudonymous mode, None in anonymous mode. Surfaced verbatim by the consent widget for user inspection.

Source

fn supported_scopes(&self) -> ConsentScope

Drives the consent widget toggle group: which scopes does this adapter actually use? Toggles for unsupported scopes are hidden, not just disabled.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§