mylogger_flutter 0.1.0
mylogger_flutter: ^0.1.0 copied to clipboard
Flutter error, navigation and HTTP telemetry for the MyLogger collector.
MyLogger Flutter #
Android/iOS Flutter telemetry using the existing MyLogger
POST /api/telemetry/collect endpoint and public project key (pk_...).
Deploy the accompanying backend changes first: they recognize source: mobile,
route flutter_error into Issues, and parse unobfuscated Dart stack frames.
No new endpoint or database column is required.
Install #
After this package is published to pub.flutter-io.cn, install it with:
flutter pub add mylogger_flutter
Before the first publication, use a local dependency:
dependencies:
mylogger_flutter:
path: ../Logger_Workspace/flutter_sdk
Initialize once, on the main isolate, before runApp:
import 'package:flutter/material.dart';
import 'package:mylogger_flutter/mylogger_flutter.dart';
late final MyLogger logger;
late final MyLoggerHttpClient api;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
logger = await MyLogger.init(
apiKey: 'pk_YOUR_PROJECT_KEY',
endpoint: Uri.parse('https://YOUR_COLLECTOR/api/telemetry/collect'),
environment: 'production',
release: '1.0.0+12', // Supply your actual app version + build.
tracePropagationOrigins: {'https://api.your-app.com'},
);
api = MyLoggerHttpClient(logger);
runApp(MaterialApp(
navigatorObservers: [MyLoggerNavigatorObserver(logger)],
routes: {'/': (_) => const Scaffold(body: Text('Home'))},
));
}
Use named routes for screen labels. With Router/go_router, attach the observer
to the appropriate navigator or call logger.trackScreen('/checkout') explicitly.
logger.trackAction('Tap Pay');
try {
final response = await api.post(Uri.parse('https://api.your-app.com/pay'));
// Handle your response normally.
} catch (error, stack) {
logger.captureException(error, stack);
}
Only requests made through MyLoggerHttpClient are tracked. Existing top-level
http.get, Dio clients, native plugin requests and other isolates are not intercepted.
HTTP duration measures time until response headers, not full body download.
Flutter framework and main-isolate dispatcher errors are captured automatically;
existing error handlers still run. Handled errors require captureException.
Android release manifests need android.permission.INTERNET. Use a collector URL
reachable from the device; device localhost is not your development computer.
Use HTTPS in production. The key is public, not an admin secret.
Delivery and privacy #
- Same
{events: [...]}envelope as the web SDK; source ismobile. - Errors, breadcrumbs, screen navigation/pageviews, actions, sessions and HTTP spans.
- Session per launch; new session after 30 minutes in the background.
- App release/environment and session OS/language context; no automatic user identity.
- Up to 200 events, 32 KiB per event, 20 per upload; periodic delivery every 10 seconds.
- Queue persisted in app support storage; failed uploads retry with exponential backoff up to 5 minutes. Bounded storage drops oldest events when full.
- Atomic file replacement; storage failures fall back to memory. Persistence is asynchronous, so an abrupt process kill can lose events not yet written.
- Delivery is best effort, with possible duplicates after ambiguous network failures.
- Bodies/headers are not recorded by the HTTP wrapper; URL query strings, credentials and fragments are removed. Paths, action labels and error messages may still contain personal data: supply safe labels and avoid sensitive values.
- Trace headers go only to explicitly allowed origins. Instrument the backend and use the same project to view a connected trace.
- Call
await logger.close()for controlled teardown; queued failures remain on disk.
Not included #
Native Android/iOS fatal-crash capture, ANRs, native symbolication, obfuscated Dart symbolication, replay, automatic tap interception, app-start/frame profiling, background-isolate hooks, Dio integration and Flutter Web support. Web Vitals are not emitted. Mobile device model/build discovery is not implemented; provide the release string yourself. Existing dashboard filters may still use web-oriented labels.
Verify #
flutter pub get
flutter analyze
flutter test
dart pub publish --dry-run
Backend contract tests from the repository root:
node --test backend/tests/flutter-ingest.test.mjs
Validated with Flutter 3.47.3 / Dart 3.13.3: the analyzer reports no issues and all three unit tests pass. Android/iOS builds and on-device behavior have not been verified; test those before production use. Older SDK versions allowed by the package constraints have not been validated.
References: Flutter error handling, HTTP client composition, app support storage.
License #
MIT. See LICENSE.