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.

SignalRecorded asNeeds
Uncaught Flutter framework errorserror log, spz.exception_handling: unhandledstart(action: ...) or installErrorHandlers
Uncaught async and platform errorserror log, spz.exception_handling: unhandledstart(action: ...) or installErrorHandlers
Time to first framespz-time-to-first-frame-flutter spanstart(action: ...)
Time to interactivespz-time-to-interactive-flutter span, once per processa navigation observer
Slow framesinfo log slow-frames, batchednothing
Frozen frameswarning log frozen-framenothing
UI isolate hangsspz-dart-isolate-hang spannothing
Time in backgroundspz-app-background spannothing
Routesview spans and screen-load spansSophonzNavigationObserver or SophonzGoRouterObserver
HTTP requestsnetwork spansSophonzHttpClient 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 a RenderFlex overflow. 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 an async callback nobody awaited. The handler returns false, so the error also continues to the default handling.

Each error becomes an error-severity log with these attributes:

AttributeValue
exception.typeThe runtime type, such as StateError
exception.messagetoString() of the error, or the framework's summary
exception.stacktraceThe Dart stack trace
exception.context, exception.libraryFor framework errors, the FlutterErrorDetails context and library
spz.exception_handlingunhandled, 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

SpanStartEnd
spz-time-to-first-frame-flutterwhen start() begins in Dartwhen the first frame is rasterized
spz-time-to-interactive-flutterthe same start timethe 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.

CaseThresholdRecord
Slow frameover 16 msCounted. Every 60 slow frames, one info log slow-frames with count, worst_build_ms, worst_raster_ms
Frozen frame700 ms or moreOne 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.

SignalAndroidiOS
Sessionsyesyes
Native crashes (JVM, NDK / Mach, signals)yesyes
ANRs / main-thread hangsANR on by defaulthang capture off by default
App startup traceyes, when started in Application.onCreate()yes, when started in the AppDelegate initializer
Network calls made by native code (OkHttp, HttpURLConnection / URLSession)yesyes
Device and app resourcesyesyes
Push notificationsFCM when enabledwhen PushNotificationCaptureService is added
Taps and screens of native viewsyesyes

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 wantCall
A caught errorlogHandledDartError(error, stack)
An error from a spawned isolateforward it and call logDartError
Timing of your own workstartSpan / stop, or recordCompletedSpan
A message or event on the timelinelogInfo, logWarning, logError, addBreadcrumb
Who the user issetUserIdentifier, addUserPersona
Context for the sessionaddSessionProperty
A screen that is not a route (tab, bottom sheet)startView / endView
A request made outside the wrappersrecordNetworkRequest
A push notification handled in DartlogPushNotification

All of these are in the API reference.

Platform differences

BehaviourAndroidiOS
Native start from the pluginThe plugin starts the SDK if the app did not (no startup timing)Never. Without the AppDelegate start, every call is a no-op
Upload timingHandled by the Android SDK's deliveryWhen a session part ends: backgrounding or next launch
setUserName, setUserEmailRecordedAccepted and ignored
PersonasKept by the Android SDKProcess lifespan; set them again after a relaunch
endSessionImmediateAt most once per 5 seconds
addSpanExporter, addLogRecordExporterForwarded 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 URLAs givenQuery string and fragment removed
HTTP methods other than GET, POST, PUT, DELETE, PATCHNot recordedRecorded as OTHER
Push notification fieldsfrom, messageId, priority, hasNotification, hasDatatitle, body (both required), subtitle, badge, category
Flutter SDK and Dart versionsPassed to the Android SDK at attachProcess 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: SIGABRT

After 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