Instrumentation
What a Flutter app reports without extra code — Dart errors, frames, isolate hangs, startup and lifecycle from the Flutter layer, and crashes, ANRs and sessions from the native SDKs — and where Android and iOS differ.
Two layers capture data in a Flutter app. The Dart layer sees what happens in Dart: errors, frames, the UI isolate, routes and HTTP clients you wrap. The native SDK sees the process: sessions, native crashes, ANRs, app startup and native network calls. The Dart layer does not upload anything; it hands every record to the native SDK over a method channel, and the native SDK stores and delivers it.
Captured by the Dart layer
Everything here starts when Sophonz.instance.start() runs.
| Signal | Recorded as | Needs |
|---|---|---|
| Uncaught Flutter framework errors | error log, spz.exception_handling: unhandled | start(action: ...) or installErrorHandlers |
| Uncaught async and platform errors | error log, spz.exception_handling: unhandled | start(action: ...) or installErrorHandlers |
| Time to first frame | spz-time-to-first-frame-flutter span | start(action: ...) |
| Time to interactive | spz-time-to-interactive-flutter span, once per process | a navigation observer |
| Slow frames | info log slow-frames, batched | nothing |
| Frozen frames | warning log frozen-frame | nothing |
| UI isolate hangs | spz-dart-isolate-hang span | nothing |
| Time in background | spz-app-background span | nothing |
| Routes | view spans and screen-load spans | SophonzNavigationObserver or SophonzGoRouterObserver |
| HTTP requests | network spans | SophonzHttpClient or SophonzInterceptor |
Routes are described in Navigation, HTTP in Networking.
Errors
With start(action: ...), two handlers are installed:
FlutterError.onError— errors reported by the framework: build, layout and paint errors such as aRenderFlexoverflow. The previous handler still runs after Sophonz records the error, so debug console output is unchanged.PlatformDispatcher.instance.onError— errors that escape everything else, such as an exception thrown in anasynccallback nobody awaited. The handler returnsfalse, so the error also continues to the default handling.
Each error becomes an error-severity log with these attributes:
| Attribute | Value |
|---|---|
exception.type | The runtime type, such as StateError |
exception.message | toString() of the error, or the framework's summary |
exception.stacktrace | The Dart stack trace |
exception.context, exception.library | For framework errors, the FlutterErrorDetails context and library |
spz.exception_handling | unhandled, or handled for logHandledDartError |
On Android the log body is Dart error and the message is in exception.message. On iOS the body is the message itself.
Errors you catch are not recorded unless you log them:
try {
await repository.sync();
} catch (error, stack) {
Sophonz.instance.logHandledDartError(error, stack);
}An error recorded as handled does not count against the error-free session rate.
CAUTION — A Dart error is not a crash
Flutter keeps running after an uncaught Dart exception, so these are error logs, not crashes, and getLastRunEndState() stays cleanExit. Crashes come from the native SDKs: an uncaught JVM or Objective-C exception, or a native signal.
Isolates
The handlers are installed on the root isolate only. An exception in an isolate you spawn is not captured, with one exception: compute rethrows the error in the calling isolate, where it is captured if nothing catches it.
For Isolate.spawn, forward errors to the root isolate through onError and record them there:
final errors = ReceivePort();
errors.listen((message) {
final pair = message as List<dynamic>;
Sophonz.instance.logDartError(
pair[0] as Object,
StackTrace.fromString(pair[1] as String),
);
});
await Isolate.spawn(parseLargeFile, path, onError: errors.sendPort);start() runs on the root isolate only, so a Sophonz.instance call made inside a spawned isolate is dropped.
Startup
| Span | Start | End |
|---|---|---|
spz-time-to-first-frame-flutter | when start() begins in Dart | when the first frame is rasterized |
spz-time-to-interactive-flutter | the same start time | the frame after the first route is pushed. Carries a route attribute |
Both measure from the Dart side. Time before Dart runs, such as process start and engine initialization, is in the native startup trace. That trace needs the native SDK started in Application.onCreate() on Android or the AppDelegate initializer on iOS.
Frames
Frame timings come from SchedulerBinding.addTimingsCallback. A frame is judged by the longer of its build and raster durations.
| Case | Threshold | Record |
|---|---|---|
| Slow frame | over 16 ms | Counted. Every 60 slow frames, one info log slow-frames with count, worst_build_ms, worst_raster_ms |
| Frozen frame | 700 ms or more | One warning log frozen-frame per frame, with build_ms, raster_ms |
Both carry a route attribute with the current route when SophonzNavigationObserver is used. A partial batch of slow frames is not flushed when the app exits.
UI isolate hangs
Flutter's UI runs on a Dart isolate, not the platform main thread, so Android ANR detection and the iOS hang detector do not see a stalled Dart event loop. A timer on the UI isolate ticks every 100 ms. When a tick arrives 700 ms or more after the previous one, the gap is recorded as a completed spz-dart-isolate-hang span with a duration_ms attribute.
Monitoring pauses while the app is in the background and restarts on resume, so a suspended process is not reported as a hang.
Lifecycle
When the app moves to the background (AppLifecycleState.paused), a spz-app-background span starts. It ends on resumed or detached.
Captured by the native SDKs
These do not depend on Dart and are configured in the native SDK.
| Signal | Android | iOS |
|---|---|---|
| Sessions | yes | yes |
| Native crashes (JVM, NDK / Mach, signals) | yes | yes |
| ANRs / main-thread hangs | ANR on by default | hang capture off by default |
| App startup trace | yes, when started in Application.onCreate() | yes, when started in the AppDelegate initializer |
| Network calls made by native code (OkHttp, HttpURLConnection / URLSession) | yes | yes |
| Device and app resources | yes | yes |
| Push notifications | FCM when enabled | when PushNotificationCaptureService is added |
| Taps and screens of native views | yes | yes |
Details and switches are in Android instrumentation and iOS instrumentation.
NOTE — Dart HTTP is invisible to native network capture
dart:io opens its own sockets, so requests from http or Dio never pass through OkHttp or URLSession. They are recorded only by the Dart wrappers. A client that delegates to URLSession, such as cupertino_http, is also seen by the Apple SDK and the same request can be recorded twice.
Native taps and screens describe the host activity or view controller, which in a Flutter app is one FlutterActivity or FlutterViewController. Screen names inside Flutter come from the navigation observers.
What needs a call from you
| You want | Call |
|---|---|
| A caught error | logHandledDartError(error, stack) |
| An error from a spawned isolate | forward it and call logDartError |
| Timing of your own work | startSpan / stop, or recordCompletedSpan |
| A message or event on the timeline | logInfo, logWarning, logError, addBreadcrumb |
| Who the user is | setUserIdentifier, addUserPersona |
| Context for the session | addSessionProperty |
| A screen that is not a route (tab, bottom sheet) | startView / endView |
| A request made outside the wrappers | recordNetworkRequest |
| A push notification handled in Dart | logPushNotification |
All of these are in the API reference.
Platform differences
| Behaviour | Android | iOS |
|---|---|---|
| Native start from the plugin | The plugin starts the SDK if the app did not (no startup timing) | Never. Without the AppDelegate start, every call is a no-op |
| Upload timing | Handled by the Android SDK's delivery | When a session part ends: backgrounding or next launch |
setUserName, setUserEmail | Recorded | Accepted and ignored |
| Personas | Kept by the Android SDK | Process lifespan; set them again after a relaunch |
endSession | Immediate | At most once per 5 seconds |
addSpanExporter, addLogRecordExporter | Forwarded at start() | Ignored; use otel: in the start options |
Flutter routes and app.screen.name | — | Not updated; other spans keep the Flutter view controller's name |
| Network span URL | As given | Query string and fragment removed |
| HTTP methods other than GET, POST, PUT, DELETE, PATCH | Not recorded | Recorded as OTHER |
| Push notification fields | from, messageId, priority, hasNotification, hasData | title, body (both required), subtitle, badge, category |
| Flutter SDK and Dart versions | Passed to the Android SDK at attach | Process properties spz_flutter_sdk_version, spz_dart_runtime_version |
CAUTION — On iOS, a foreground debug run shows nothing yet
The Apple SDK writes spans and logs to disk and uploads them when the session part ends. Send the app to the background, or relaunch it, before looking for data.
WebView
The native SDKs can share their session with a page in a WebView through a bridge (WebView integration). That bridge is not wired for webview_flutter in 0.1.0: the plugin does not receive the platform WebView instance, so a Flutter WebView page starts its own session in the Browser SDK.
Verifying capture
package:sophonz/sophonz_samples.dart has triggers for testing a build. Use them in a debug or internal build only.
import 'package:sophonz/sophonz_samples.dart';
SophonzSamples.triggerUncaughtException(); // Dart error log
SophonzSamples.triggerUncaughtExceptionAsync();
SophonzSamples.triggerNativeSdkError(); // native crash on both platforms
SophonzSamples.triggerAnr(); // Android only: blocks the main thread for 10 s
SophonzSamples.triggerRaisedSignal(); // iOS only: SIGABRTAfter a native crash, relaunch the app. The crash is uploaded on the next launch.
Next
- Navigation — route tracking with Navigator or go_router
- Networking — HTTP capture and trace propagation