Skip to main content

Flutter RUM

The Oodle Flutter SDK records how people use your Android and iOS app: the screens they open, the taps they make, the requests the app sends, the errors and crashes they see, and a replay of each session. The data goes to the same RUM Explorer, Issues and Session Replay pages as browser RUM.

Requirements​

  • Flutter 3.38 or later and Dart 3.10 or later.
  • Android 7.0 (API level 24) or later, and iOS 15.0 or later.
  • A RUM API key. Create it in Settings > API Keys with the RUM role. A RUM key can only write RUM data, so it is safe in an app.

Installation​

flutter pub add oodle_flutter

The SDK contains native code. Stop the app and build it again after you install it: a hot reload or a hot restart does not load native code.

Quick start​

Start the app with OodleRum.runApp. It starts the SDK, which records Dart and Flutter errors, then runs your app in a zone that records print lines. Put OodleRumApp above MaterialApp: it records taps and is the root of the session replay.

import 'package:flutter/material.dart';
import 'package:oodle_flutter/oodle_flutter.dart';

Future<void> main() async {
await OodleRum.runApp(
OodleRumConfig(
instanceId: '<YOUR_INSTANCE_ID>',
apiKey: '<YOUR_RUM_API_KEY>',
endpoint: 'https://<YOUR_COLLECTOR_DOMAIN>',
service: 'my-app',
env: 'production',
allowedTracingUrls: ['api.example.com'],
),
() => runApp(const OodleRumApp(child: MyApp())),
);
}

Call OodleRum.runApp first in main, before WidgetsFlutterBinding.ensureInitialized(): it makes the binding itself. Code that needs the binding (Firebase, plugins) goes in the function that calls runApp. When the app makes the binding before OodleRum.runApp, the SDK runs the app without the zone, and records debugPrint lines but not print lines.

To catch errors with your own handler, pass it as onError instead of a runZonedGuarded in your function. The binding keeps its zone for all input and frame callbacks, so a zone made inside the function does not get the errors of the UI:

OodleRum.runApp(
config,
() => runApp(const OodleRumApp(child: MyApp())),
onError: report,
);

Screen views​

Add an OodleNavigatorObserver to each navigator. It starts a view for each page route, and stops the view when the route goes.

MaterialApp(
navigatorObservers: [OodleNavigatorObserver()],
home: const HomeScreen(),
);

With go_router, give it to the router:

final router = GoRouter(
observers: [OodleNavigatorObserver()],
routes: [/* ... */],
);

A navigator can have only one observer instance, so make a new one for each navigator, also for a nested Navigator. With go_router, GoRouter(observers:) is for the root navigator only: give each ShellRoute and StatefulShellBranch its own instance in its observers.

The view name is the route name (RouteSettings.name) without its query string. A route without a name is not a view, so give each route a name:

Navigator.of(context).push(
MaterialPageRoute(
settings: const RouteSettings(name: 'Cart'),
builder: (context) => const CartScreen(),
),
);

Named routes (routes: and pushNamed) and go_router routes have names already.

Dialogs, popups and bottom sheets are not views: only a PageRoute is. Change this with routeFilter.

Taps​

OodleRumApp records each tap on a widget that has a tap handler. The action name is the kind of widget and a label, for example Button(Checkout), IconButton(Search) or ListTile(unknown). The label is the first of:

  1. The name of an OodleActionName around the widget.
  2. The tooltip or semantics label of the widget (useSemanticsLabel).
  3. The text inside the widget, then the semantics label of its icon.

When the replay masks all text (TextAndInputPrivacy.maskAll, the default), the label is the OodleActionName name only, and a tap without one is unknown. Inside OodlePrivacy(level: PrivacyLevel.allow), and with a lower privacy level, the semantics label and the text name taps too. Give the important widgets an OodleActionName:

OodleActionName(
name: 'Checkout',
child: ElevatedButton(onPressed: checkout, child: Text(cart.total)),
);

Three taps on one widget on one screen in one second are a rage tap. The rage tap is sent in addition to the three taps.

Privacy​

The replay records no text of the app by default (TextAndInputPrivacy.maskAll), and the SDK keeps that text out of tap names. Set a lower level for the whole app in SessionReplayConfig:

textAndInputPrivacyEffect
TextAndInputPrivacy.maskAll (default)Mask all text and inputs
TextAndInputPrivacy.maskAllInputsMask every input
TextAndInputPrivacy.maskSensitiveInputsMask passwords, emails and phone numbers

Passwords and other sensitive inputs are masked at every level. Images are recorded as placeholders. To set the privacy of one part of a screen, wrap it in OodlePrivacy:

OodlePrivacy(
level: PrivacyLevel.hidden,
child: PaymentCard(card: card),
);

PrivacyLevel.hidden replaces the content with an empty box, PrivacyLevel.mask masks its text, and PrivacyLevel.allow shows its text.

To change or drop an event before it is queued, use beforeSend. Return the event to keep it, or null to drop it. A request URL (url_full) is sent with its query string. To remove tokens and IDs from it:

beforeSend: (event) {
final url = event['url_full'];
if (url is String) event['url_full'] = url.split(RegExp('[?#]')).first;
return event;
},

Session replay​

The SDK records each screen as a wireframe: the position, color and text of each widget. Replays play in the Session Replay page.

sessionReplay: SessionReplayConfig(
sampleRate: 10,
textAndInputPrivacy: TextAndInputPrivacy.maskAllInputs,
touchPrivacy: TouchPrivacy.show,
startRecordingImmediately: true,
),
SettingDefaultDescription
enabledtrueRecord replays
sampleRate10Percentage of recorded sessions that also record a replay
textAndInputPrivacymaskAllSee Privacy
touchPrivacyTouchPrivacy.showshow or hide the touches
startRecordingImmediatelytrueWith false, recording waits for OodleSessionReplay.start()

Start and stop recording with OodleSessionReplay.start() and OodleSessionReplay.stop(). Use SessionReplayConfig.disabled to turn replay off.

Distributed tracing​

The SDK records the HTTP requests that the app makes with dart:io, which includes package:http and dio. It adds trace headers to requests whose URL matches allowedTracingUrls, and puts the trace ID on the resource event.

An entry is a String, a RegExp, a bool Function(String url) or a TracingUrl. A string without a scheme matches a host and its subdomains. A string with a scheme matches the start of the URL. Choose the header formats with TracingUrl:

allowedTracingUrls: [
TracingUrl(
'api.example.com',
propagators: [Propagator.tracecontext, Propagator.datadog],
),
],

Formats: tracecontext (W3C traceparent), b3, b3multi and datadog.

Readable stack traces​

An obfuscated release build has no Dart function names, and R8 renames the Java classes of the Android build. Build with --obfuscate --split-debug-info, then upload the Dart symbols files and the R8 mapping after each release build. Use the version and build number that the app sends: by default, the two parts of the version in pubspec.yaml (1.4.0+112). Oodle then shows errors and crashes with source files and lines.

export OODLE_API_URL=https://<YOUR_INSTANCE>.api.oodle.ai
export OODLE_INSTANCE=<YOUR_INSTANCE_ID>
export OODLE_API_KEY=<YOUR_API_KEY>

# Android
flutter build appbundle --obfuscate --split-debug-info=build/symbols
dart run oodle_flutter:upload --service my-app --version 1.4.0 --build 112 \
--dart-symbols build/symbols \
--r8-mapping build/app/outputs/mapping/release/mapping.txt

# iOS
flutter build ipa --obfuscate --split-debug-info=build/symbols
dart run oodle_flutter:upload --service my-app --version 1.4.0 --build 112 \
--dart-symbols build/symbols

--dart-symbols takes the --split-debug-info directory (it uploads one .symbols file for each target architecture) or one .symbols file. Use an API key with the Editor or Admin role. The RUM key that is in the app cannot upload files.

Configuration​

OptionTypeDefaultDescription
instanceIdStringrequiredOodle instance ID
apiKeyStringrequiredRUM API key
endpointStringrequiredCollector URL
serviceStringrequiredApplication name
envString''Environment
versionString?native app versionApp version
buildString?native build numberApp build
trackingConsentTrackingConsentgrantedgranted, pending or notGranted
sessionSampleRatenum100Percentage of sessions to record
trackInteractionsbooltrueRecord taps (needs OodleRumApp)
useSemanticsLabelbooltrueName taps by semantics label and tooltip
trackResourcesbooltrueRecord HTTP requests made with dart:io
trackErrorsbooltrueRecord Dart and Flutter errors
trackConsolebooltrueRecord debugPrint lines, and print lines with error or warning words. print lines need OodleRum.runApp to make the binding (see Quick start)
allowedTracingUrlsList<Object>[]Requests that get trace headers
traceSampleRatenum100Percentage of traced requests marked as sampled
sendClientSpansbooltrueSend a client span for each sampled traced request
nativeCrashReportingbooltrueRecord native crashes
trackAnrsbooltrueRecord ANRs (Android) and app hangs (iOS)
anrThresholdMsint?5000 Android, 2000 iOSMain thread block that counts
longTaskThresholdMsint200UI isolate block that counts as a long task; 0 turns it off
vitalsbooltrueFrame rate, frozen frames, memory and CPU per view
tagsMap<String, Object>{}Tags on every event
sessionReplaySessionReplayConfigon, 10%Replay settings (see Session replay)
flushIntervalMsint15000Time between two sends of queued events
verbosityVerbositywarnSDK log level
beforeSendBeforeSend?noneChange or drop an event before it is queued

What is collected​

EventContents
ViewScreen name, time on screen, app start time (cold start), refresh rate, slow and frozen frames, memory, CPU
ActionTaps, named by the kind of widget and a label (see Taps), rage taps, custom actions
ResourceHTTP requests: full URL with its query string, method, status, duration, size, trace ID
ErrorDart and Flutter errors, native crashes (sent on the next start), ANRs, app hangs, failed requests
Long taskUI isolate blocks longer than longTaskThresholdMs
ConsoledebugPrint lines, and print lines with error or warning words when OodleRum.runApp makes the binding
VisibilityThe app going to the background and coming back

Each event also has the device brand and model, the OS and its version, the app version and build, the connection type, and the tags.

Troubleshooting​

  • No data: check that the app was built again after the install, and that OodleRumApp is above MaterialApp. Set verbosity: Verbosity.debug to see the SDK log.
  • No screen views: check that each navigator has its own OodleNavigatorObserver and that the routes have names.

Support

If you need assistance or have any questions, please reach out to us through: