ispectify_ws 5.2.0-dev.17
ispectify_ws: ^5.2.0-dev.17 copied to clipboard
Provider-agnostic WebSocket diagnostics for ISpect — connection lifecycle, sent and received frame logging, session grouping, and redaction for any WebSocket client.
ispectify_ws is the provider-agnostic WebSocket diagnostics layer for the ISpect toolkit. It captures sent and received frames, connection-state transitions, and errors — for any WebSocket client — and redacts sensitive data before logging. The published package depends only on ispectify; you keep your own WebSocket client dependency.
- Frame-level capture for sent and received messages (
ws-sent/ws-received). - Connection lifecycle logging via
ws-state(connecting / open / closing / closed / reconnecting). - Error logging with stack traces (
ws-error); one correlation id per connection session. - Same redaction engine as the HTTP interceptors.
Install #
dependencies:
ispectify: ^5.2.0-dev.17
ispectify_ws: ^5.2.0-dev.17
# plus your WebSocket client, e.g.
# ws: ^1.0.0 | web_socket_channel: ^3.0.0 | socket_io_client: ^3.0.0
Quick start #
Bind any client to the WsDiagnosticsSink port. Metrics and state are optional — push whatever your client can report:
import 'package:ispect/ispect.dart';
import 'package:ispectify_ws/ispectify_ws.dart';
final diagnostics = WsDiagnostics(logger: ISpect.logger);
diagnostics
..newConnection() // starts a fresh correlation session
..onStateChanged(WsConnectionState.open, url: url);
channel.stream.listen(
(message) => diagnostics.onReceived(message, url: url),
onError: (Object e, StackTrace st) => diagnostics.onError(e, st, url: url),
onDone: () => diagnostics.onStateChanged(WsConnectionState.closed, url: url),
);
// Outbound: call diagnostics.onSent(data, url: url) before sending a frame.
Ready-to-copy adapters #
The package example ships thin adapters that wire a concrete client to WsDiagnostics — copy the one you need into your app (and add that client to your own pubspec.yaml):
| Client | Adapter |
|---|---|
ws (plugfox) |
example/lib/interceptors/ws_interceptor.dart |
web_socket_channel |
example/lib/interceptors/web_socket_channel_interceptor.dart |
socket_io_client |
example/lib/interceptors/socket_io_interceptor.dart |
Migrating from 5.x?
ISpectWSInterceptormoved out of the published package intoexample/lib/interceptors/ws_interceptor.dart. Copy it in and addwsto your app —ISpectWSInterceptorSettingsand thews-sent/ws-received/ws-errorkeys are unchanged. Seedocs/DEPRECATIONS.md.
Settings #
const settings = ISpectWSInterceptorSettings(
enabled: true,
printSentData: true,
printReceivedData: true,
printReceivedMessage: true,
printErrorData: true,
printErrorMessage: true,
enableRedaction: true,
);
final diagnostics = WsDiagnostics(logger: ISpect.logger, settings: settings);
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 same redactor runs beyond the initial capture. Supported exports, clipboard helpers, cURL generation, and observer payloads all pass through the same pipeline before data leaves the debug session.
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.
Custom keys and patterns #
import 'package:ispectify/ispectify.dart';
final redactor = RedactionService(
sensitiveKeys: {
...defaultSensitiveKeys,
'x-custom-secret',
'internal_token',
},
sensitiveKeyPatterns: [
RegExp(r'my_app_secret_\w+', caseSensitive: false),
],
// Keys where the value is replaced entirely instead of edge-masked.
fullyMaskedKeys: {'filename'},
placeholder: '***',
visibleEdgeLength: 3,
redactBinary: true,
redactBase64: true,
);
Ignoring defaults #
final redactor = RedactionService(
// `?mobile=true` is a platform flag, not a phone number.
ignoredKeys: {'mobile', 'platform_token'},
ignoredValues: {'<test-token>', 'public-api-key'},
);
Disabling #
Each interceptor accepts enableRedaction: false on its settings object. See the per-package README for the exact settings type.
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.