easyslo 0.1.0
easyslo: ^0.1.0 copied to clipboard
Lightweight outcome monitoring for Flutter. Persistent batching, offline retries, and success-rate SLOs.
EasySLO Flutter SDK #
An Android/iOS Flutter package for reporting operation success and failure with a persistent offline queue. Track checkout, sign-in, and other user journeys against success-rate SLOs at easyslo.com.
Install and initialize #
dependencies:
easyslo: ^0.1.0
Or run flutter pub add easyslo. Then run flutter pub get. The SDK’s Android plugin declares the internet permission, which is merged into your app automatically. No manual Android manifest edit or runtime permission prompt is needed.
Use an SDK key from the dashboard’s SDK keys page. The SDK manages the service address:
import 'package:flutter/widgets.dart';
import 'package:easyslo/easyslo.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Sdk.init(const String.fromEnvironment('MOBILESLO_KEY'));
runApp(const MyApp());
}
Build/run with --dart-define=MOBILESLO_KEY=YOUR_SDK_KEY. Replace MyApp with your root widget. Awaiting initialization completes local setup so the first startup outcomes can be captured; it does not wait for network delivery. Setup failures are recorded in Sdk.diagnostics and your app continues. Only Android and iOS are supported.
The dashboard’s Setup page walks through installation, initialization, and first-event verification. Get your SDK key at easyslo.com.
Report outcomes #
New event keys automatically appear in the dashboard with a 95% SLO target. Open a monitor to adjust its target.
Sdk.success('checkout');
Sdk.failure('checkout', e);
failure now takes an Exception, replacing the former cause string. Pass the original exception from your operation:
try {
await completeCheckout();
await Sdk.success('checkout');
} on Exception catch (exception) {
await Sdk.failure('checkout', exception);
}
The SDK stores one of five stable cause buckets:
| Cause | Recognized failures |
|---|---|
NETWORK |
Dart SocketException/TlsException (including TLS handshakes), http.ClientException, and Dio connection/certificate errors |
TIMEOUT |
Dart TimeoutException and Dio connection/send/receive/transform timeouts |
HTTP_4XX |
HTTP status 400–499, including authentication failures and rate limits |
HTTP_5XX |
HTTP status 500–599 |
OTHER |
Unrecognized exceptions, parsing/business errors, and explicitly reported cancellations |
Dio response status codes are detected automatically. Dio exceptions with an unknown type can also expose an underlying standard exception. For other HTTP clients, supply a known response status explicitly:
await Sdk.failure('checkout', exception, statusCode: response.statusCode);
A supplied 4xx/5xx status takes precedence over exception classification. Statuses outside those ranges fall back to the exception. dart:io's HttpException and package:http's ClientException do not expose HTTP response status codes; the SDK never guesses a status from their messages. Only the bucket is persisted/uploaded, not the exact status, exception, message, stack trace, URL, headers, or response body. Intentional cancellations should be skipped by the caller; if reported, Dio cancellations and http.RequestAbortedException map to OTHER. Error objects are not accepted by this API; catch exceptions with on Exception catch (exception).
Each call creates a new UUID and persists an immutable occurrence with the app’s version/build and platform. Calls return Future<void>: awaiting confirms the persistence attempt has completed, not server delivery. Initialization, capture, flush, and cleanup contain SDK errors; inspect diagnostics for initialization, storage, and delivery failures. Calls before initialization are ignored and counted in Sdk.callsBeforeInitialization. Initialization failures leave monitoring disabled; the app can continue normally. Concurrent initialization calls share the in-progress attempt. Repeating initialization with the same key and namespace leaves the current client, timer, observer, and queue intact. Initialization and disposal are serialized so disposing during setup cannot leave a client running. Await initialization before reporting if you need to capture the first startup outcomes.
Choose whether business retries count as separate attempts or only report the final outcome, then instrument consistently. Transport retries reuse IDs. Event keys must match [A-Za-z0-9_.:-]{1,128} and must not contain customer data or secrets. Failure causes are generated by the SDK; generic business exceptions map to OTHER. Missing calls, abandoned operations, and crashes are not automatically failures.
await Sdk.flush(); // Best-effort; respects backoff and Retry-After.
final status = Sdk.diagnostics.toMap();
await Sdk.dispose(); // Unregister lifecycle observer and close resources.
Diagnostics include pending, accepted, duplicates, rejected, dropped, expired, retries, storage errors, initialization errors, invalid calls, last error, and next retry time. Counters describe the current process. They contain no business payloads and are not uploaded automatically.
Delivery behavior #
- Async SQLite persistence, one sender per initialized client, main isolate only.
- Flush every 15 seconds, after 50 queued events, on initialization, and on resume/inactive/pause.
- Up to 50 events and roughly 60 KiB per request; request timeout 15 seconds; bounded drain of ten batches.
- Exponential backoff with jitter, numeric/date
Retry-Aftersupport, and a 15-minute pause for invalid/revoked credentials. HTTP 413 reduces batch size. - Delete only a complete, matching, validated per-event acknowledgment. Accepted/duplicate results and terminal event rejections are removed. Missing/unknown/malformed responses retain the entire batch.
- Seven-day local expiry; queue bounded to 10,000 events or 10 MiB. At capacity, oldest rows are removed in groups of 100 and counted as dropped.
- Metadata is captured once. The SDK reads the installed app version and build number using
package_info_plusand sendsapp_versionasversion+buildNumber(for example,1.5.0+50). App upgrades, retries, and rebatching do not relabel queued events. Select that version in the dashboard’s app-version dropdown to filter SLOs, hourly usage, and error causes. - Mobile operating systems can suspend execution immediately on backgrounding. Lifecycle flush is best effort; SQLite data survives for the next app session. No native background scheduler or guaranteed delivery deadline.
SDK calls should stay in the initialized main isolate. Do not create parallel SDK senders from background isolates. The SDK has no automatic crash reporting, session replay, or persistent device identifiers.
Key rotation #
By default, queue files are isolated by endpoint and key. This prevents events from being accidentally uploaded into another project/environment. Changing a key opens a separate queue; the previous queue is not automatically migrated or drained.
To preserve a queue through rotation, choose a stable namespace before the first release:
await Sdk.init(key,
queueNamespace: 'my-app-production',
);
Reuse that namespace only for replacement keys in the same project and environment. Never share it between production and development. Ship the replacement key before revoking the old one and allow an overlap period. A key revoked before an old app upgrades prevents that app from delivering its queue.
SDK development and self-hosting #
App integrations do not supply an endpoint. The SDK uses https://easyslo.com over HTTPS. SDK maintainers and self-hosted builds can select a service at build time with --dart-define=MOBILESLO_INGEST_ORIGIN=https://your-worker.workers.dev; this is optional and not part of Sdk.init.
For local SDK development, the build override accepts HTTP only on localhost, 127.0.0.1, and the Android emulator host 10.0.2.2. Physical devices need a reachable HTTPS service. Local Android HTTP testing may require a debug-only network security configuration; keep release configuration HTTPS-only. Keys must belong to the selected service. Queue files remain scoped by service and key/namespace.
Example and tests #
example/lib/main.dart shows a minimal integration. To generate platform scaffolding for the example, run flutter create --platforms=android,ios --project-name easyslo_example . from sdk/example/, then run with the key dart define above. The first valid checkout upload creates its monitor automatically.
flutter pub get
flutter analyze
flutter test
Tests cover exception bucketing, payload privacy, bucket persistence across restarts/retries, immutable retries, offline recovery, quota backoff, duplicate flushes, malformed acknowledgments, auth failures, batch splitting, expiry, and SQLite close/reopen persistence. Background/battery behavior still needs testing on physical Android/iOS devices.