ispectify_db 7.0.0-dev2
ispectify_db: ^7.0.0-dev2 copied to clipboard
Passive database observability for ISpect with operation tracing, timings, slow-query logs, result projection, and redaction.
ispectify_db adds passive database observability to the ISpect toolkit. It traces SQL statements, ORM operations, and KV-store calls through a single dbTrace extension with timing, row counts, slow-query detection, and redaction.
- Works with any driver. sqflite, drift, Isar, ObjectBox, shared_preferences, hive, and the rest. Wrap the call and the tracing is automatic.
- Argument redaction by configured keys.
- A slow-query threshold emits a separate log entry so perf outliers stand out.
- Optional stack trace capture on errors, paid for only when an error happens.
- Pure Dart. No Flutter binding required.
Install #
dependencies:
ispectify: ^7.0.0-dev2
ispectify_db: ^7.0.0-dev2
Quick start #
Pass configuration at the traced call site:
import 'package:ispectify_db/ispectify_db.dart';
const dbConfig = ISpectDbConfig(
sampleRate: 1.0,
redact: true,
attachStackOnError: true,
slowThreshold: Duration(milliseconds: 400),
);
Then wrap each storage call with dbTrace:
import 'package:sqflite/sqflite.dart';
final rows = await ISpect.logger.dbTrace<List<Map<String, Object?>>>(
source: 'sqflite',
operation: 'query',
statement: 'SELECT * FROM users WHERE id = ?',
args: [userId],
table: 'users',
run: () => db.rawQuery('SELECT * FROM users WHERE id = ?', [userId]),
projectResult: (rows) => {'rows': rows.length},
config: dbConfig,
);
source and operation become the grouping key in the log viewer. projectResult lets you record "just the counts" instead of dumping row contents.
Configuration #
| Field | Default | What it does |
|---|---|---|
sampleRate |
1.0 |
Fraction of calls to log. 0.1 keeps 10% of them. |
redact |
true |
Mask sensitive keys in args and statement. |
redactKeys |
built-in set | Override the redaction key list. |
attachStackOnError |
true |
Capture and log a stack trace on failure. |
slowThreshold |
null |
Re-emit durations above the threshold as a db-slow-query entry. (Renamed from slowQueryThreshold in 5.0.) |
const dbConfig = ISpectDbConfig(
redact: true,
redactKeys: ['password', 'token', 'secret'],
slowThreshold: Duration(milliseconds: 250),
);
redactKeys is an explicit local replacement for this trace. Omit it to use the current global ISpectRedaction.service.
Data redaction #
Sensitive data is masked before it reaches logs or observers. Redaction is on by default. The built-in rules cover auth headers, tokens, passwords, API keys, cookies, common PII (SSN, passport, driver's license), financial data (credit cards, IBAN), and phone numbers.
The default policy is a single source of truth. Configure it once and core logs, traces, persistence, network and database adapters, BLoC and Riverpod observers, supported exports, clipboard helpers, and cURL generation resolve it when each diagnostic operation runs.
Redaction works best paired with focused capture. Keep body and header logging off unless you actually need the payload, and register project-specific keys for the business identifiers only your application understands.
Global configuration #
import 'package:ispectify/ispectify.dart';
ISpectRedaction.configure(
service: RedactionService(
additionalSensitiveKeys: {
'x-custom-secret',
'internal_token',
},
additionalSensitiveKeyPatterns: [
RegExp(r'my_app_secret_\w+', caseSensitive: false),
],
fullyMaskedKeys: {'filename'},
placeholder: '***',
visibleEdgeLength: 3,
),
);
additionalSensitiveKeys and additionalSensitiveKeyPatterns extend the built-in policy. Use sensitiveKeys or sensitiveKeyPatterns only when you intentionally want to replace the corresponding defaults:
final replacementPolicy = RedactionService(
sensitiveKeys: {
'x-custom-secret',
'internal_token',
},
sensitiveKeyPatterns: [
RegExp(r'my_app_secret_\w+', caseSensitive: false),
],
);
Flutter apps can pass the same policy as ISpect.run(redactionService: ...); ISpect.dispose() restores the policy that was active before that run. An explicit RedactionService supplied to one integration stays local and takes precedence over the global policy. Existing integrations without an explicit service pick up later global reconfiguration. The policy is scoped to the current Dart isolate.
Local exceptions #
final redactor = RedactionService(
ignoredKeys: {'mobile', 'platform_token'},
ignoredValues: {'<test-token>', 'public-api-key'},
);
Disabling #
ISpectRedaction.configure(enabled: false) is the global content-masking opt-out. Each interceptor also accepts enableRedaction: false on its settings object for a local opt-out. Size limits, non-executing snapshots, private-storage checks, and the compile-time ISPECT_ENABLED gate remain enforced.
Only disable redaction in isolated local or deterministic test environments. Exported sessions and observer events should be handled according to the data they contain.
The ISpect toolkit #
ISpect is a modular monorepo. Pick the packages your project needs. Each one works on its own.
| Package | What it does |
|---|---|
ispect |
Flutter UI: debug panel, log viewer, navigation observer, inspector integration. |
ispect_layout |
Visual layout inspector with sizes, constraints, decorations, compare mode, and a color picker. |
ispectify |
Pure-Dart logging core: typed log entries, filtering, tracing, observers. |
ispectify_dio |
Dio HTTP interceptor with automatic redaction. |
ispectify_http |
http package interceptor with automatic redaction. |
ispectify_ws |
Provider-agnostic WebSocket capture (any client) with automatic redaction. |
ispectify_db |
Database operation tracing for SQL, ORMs, and KV stores. |
ispectify_bloc |
BLoC event, state, transition, and error observer. |
ispectify_riverpod |
Riverpod provider add, update, dispose, and failure observer. |
Contributing #
Contributions are welcome. See CONTRIBUTING.md for guidelines, and open issues or pull requests at the ISpect repository.
License #
MIT. See LICENSE.