Flutter monitoring is in beta.
Datadog Real User Monitoring (RUM) enables you to visualize and analyze the real-time performance and user journeys of your Flutter application’s individual users.
RUM supports monitoring for mobile Flutter Android and iOS applications.
iOS SDK | Android SDK | Browser SDK |
---|---|---|
1.11.1 | 1.13.0 | v4.11.2 |
Your iOS Podfile must have use_frameworks!
(which is true by default in Flutter) and target iOS version >= 11.0.
On Android, your minSdkVersion
must be >= 19, and if you are using Kotlin, it should be version >= 1.5.31.
⚠️ Datadog support for Flutter Web is still in early development
On Web, add the following to your index.html
under your head
tag:
<script type="text/javascript" src="https://www.datadoghq-browser-agent.com/datadog-logs-v4.js"></script>
<script type="text/javascript" src="https://www.datadoghq-browser-agent.com/datadog-rum-slim-v4.js"></script>
This loads the CDN-delivered Datadog Logging and RUM Browser SDKs. Note that the synchronous CDN-delivered version of the Browser SDK is the only version supported by the Flutter plugin.
- In the Datadog app, navigate to UX Monitoring > RUM Applications > New Application.
- Choose
Flutter
as the application type. - Provide an application name to generate a unique Datadog application ID and client token.
{{< img src="real_user_monitoring/flutter/image_flutter.png" alt="Create a RUM application in Datadog workflow" style="width:90%;">}}
To ensure the safety of your data, you must use a client token. For more information about setting up a client token, see the Client Token documentation.
Create a configuration object for each Datadog feature (such as Logging, Tracing, and RUM) with the following snippet. By not passing a configuration for a given feature, it is disabled.
// Determine the user's consent to be tracked
final trackingConsent = ...
final configuration = DdSdkConfiguration(
clientToken: '<CLIENT_TOKEN>',
env: '<ENV_NAME>',
site: DatadogSite.us1,
trackingConsent: trackingConsent,
nativeCrashReportEnabled: true,
loggingConfiguration: LoggingConfiguration(
sendNetworkInfo: true,
printLogsToConsole: true,
),
tracingConfiguration: TracingConfiguration(
sendNetworkInfo: true,
),
rumConfiguration: RumConfiguration(
applicationId: '<RUM_APPLICATION_ID>',
)
);
You can initialize RUM using one of two methods in the main.dart
file.
-
Use
DatadogSdk.runApp
, which automatically sets up error reporting and resource tracing.await DatadogSdk.runApp(configuration, () async { runApp(const MyApp()); })
-
Alternatively, you can manually set up error tracking and resource tracking. Because
DatadogSdk.runApp
callsWidgetsFlutterBinding.ensureInitialized
, if you are not usingDatadogSdk.runApp
, you need to call this method prior to callingDatadogSdk.instance.initialize
.runZonedGuarded(() async { WidgetsFlutterBinding.ensureInitialized(); final originalOnError = FlutterError.onError; FlutterError.onError = (details) { FlutterError.presentError(details); DatadogSdk.instance.rum?.handleFlutterError(details); originalOnError?.call(details); }; await DatadogSdk.instance.initialize(configuration); runApp(const MyApp()); }, (e, s) { DatadogSdk.instance.rum?.addErrorInfo( e.toString(), RumErrorSource.source, stackTrace: s, ); });
After initializing Datadog with a LoggingConfiguration
, you can use the default instance of logs
to send logs to Datadog.
DatadogSdk.instance.logs?.debug("A debug message.");
DatadogSdk.instance.logs?.info("Some relevant information?");
DatadogSdk.instance.logs?.warn("An important warning…");
DatadogSdk.instance.logs?.error("An error was met!");
You can also create additional loggers with the createLogger
method:
final myLogger = DatadogSdk.instance.createLogger(
LoggingConfiguration({
loggerName: 'Additional logger'
})
);
myLogger.info('Info from my additional logger.');
Tags and attributes set on loggers are local to each logger.
The Datadog Flutter Plugin can automatically track named routes using the DatadogNavigationObserver
on your MaterialApp.
MaterialApp(
home: HomeScreen(),
navigatorObservers: [
DatadogNavigationObserver(DatadogSdk.instance),
],
);
This works if you are using named routes or if you have supplied a name to the settings
parameter of your PageRoute
.
Alternately, you can use the DatadogRouteAwareMixin
property in conjunction with the DatadogNavigationObserverProvider
property to start and stop your RUM views automatically. With DatadogRouteAwareMixin
, move any logic from initState
to didPush
.
You can enable automatic tracking of resources and HTTP calls from your RUM views using the Datadog Tracking HTTP Client package. Add the package to your pubspec.yaml
, and add the following to your initialization:
final configuration = DdSdkConfiguration(
// configuration
firstPartyHosts: ['example.com'],
)..enableHttpTracking()
In order to enable Datadog Distributed Tracing, the DdSdkConfiguration.firstPartyHosts
property in your configutation object must be set to a domain that supports distributed tracing. You can also modify the sampling rate for Datadog distributed tracing by setting the tracingSamplingRate
on your RumConfiguration
.
Before data is uploaded to Datadog, it is stored in cleartext in your application's cache directory. This cache folder is protected by Android's Application Sandbox, meaning that on most devices, this data can't be read by other applications. However, if the mobile device is rooted, or someone tampers with the Linux kernel, the stored data might become readable.
Before data is uploaded to Datadog, it is stored in cleartext in the cache directory (Library/Caches
)
of your application sandbox, which can't be read by any other app installed on the device.
Pull requests are welcome. First, open an issue to discuss what you would like to change.
For more information, read the Contributing guidelines.
For more information, see Apache License, v2.0.
{{< partial name="whats-next/whats-next.html" >}}
client