Skip to content

Proposal: Built-in Diagnostics Collection in sqlite-core #155

@khawarizmus

Description

@khawarizmus

Problem Statement

Currently, diagnostics collection requires SDK-level interception. The diagnostics app uses adapters like RecordingStorageAdapter (JS) and RustClientInterceptor (Rust) that wrap storage adapters to track bucket (size, operations, status) and table (row counts, data sizes) diagnostics.

This approach has limitations:

  • SDK-specific: Each SDK must implement its own interception layer
  • Inconsistency: Different SDKs may collect different metrics
  • Complexity: Requires wrapping/hijacking storage adapters

Proposed Solution

Move diagnostics collection into sqlite-core by:

  • Adding a SQL function (e.g., powersync_enable_diagnostics(enable BOOLEAN)) to enable/disable collection
  • Creating internal diagnostics tables (e.g., ps_diagnostics_buckets, ps_diagnostics_tables) that are automatically populated
  • Using SQLite hooks/triggers to collect metrics from existing PowerSync operations

Benefits

  • Universal: All SDKs benefit automatically
  • Simple: SDKs only need to invoke the function if a flag is present, then query the tables
  • Consistent: Same diagnostics across all platforms
  • Maintainable: Single implementation in sqlite-core
  • Performance: Can be optimized at the core level
  • Platform-agnostic tooling: Enables consistent diagnostics across platforms (diagnostics app, Nuxt module, future Chrome extension, Flutter devtools) without platform-specific interception

Possible API

-- Enable diagnostics
SELECT powersync_enable_diagnostics(1);

-- Disable diagnostics (stops collection, tables remain)
SELECT powersync_enable_diagnostics(0);

-- Enable diagnostics (with optional clear)
SELECT powersync_enable_diagnostics(1, 1);  -- enable and clear existing data
SELECT powersync_enable_diagnostics(1, 0);  -- enable without clearing

-- Clear all diagnostics
SELECT powersync_clear_diagnostics();

-- Or clear specific tables (if needed)
SELECT powersync_clear_diagnostics('buckets');
SELECT powersync_clear_diagnostics('tables');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions