Overview
Datadog Real User Monitoring (RUM) enables you to visualize and analyze the real-time performance and user journeys of your application’s individual users.
Setup
Specify application details in the UI
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.
To disable automatic user data collection for either client IP or geolocation data, uncheck the boxes for those settings. For more information, see RUM Flutter Data Collected.
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.
Instrument your application
To initialize the Datadog Flutter SDK for RUM, see Setup.
Automatically track views
Flutter Navigator v1
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
.
If you are not using named routes, you can use DatadogRouteAwareMixin
in conjunction with the DatadogNavigationObserverProvider
widget to start and stop your RUM views automatically. With DatadogRouteAwareMixin
, move any logic from initState
to didPush
.
Flutter Navigator v2
If you are using Flutter Navigator v2.0, which uses the MaterialApp.router
named constructor, the setup varies based on the routing middleware you are using, if any. Since go_router, uses the same observer interface as Flutter Navigator v1, so the DatadogNavigationObserver
can be added to other observers as a parameter to GoRouter
.
final _router = GoRouter(
routes: [
// Your route information here
],
observers: [
DatadogNavigationObserver(datadogSdk: DatadogSdk.instance),
],
);
MaterialApp.router(
routerConfig: _router,
// Your remaining setup
)
For examples that use routers other than go_router
, see Advanced Configuration - Automatic View Tracking.
Renaming Views
For all setups, you can rename views or supply custom paths by providing a viewInfoExtractor
callback. This function can fall back to the default behavior of the observer by calling defaultViewInfoExtractor
. For example:
RumViewInfo? infoExtractor(Route<dynamic> route) {
var name = route.settings.name;
if (name == 'my_named_route') {
return RumViewInfo(
name: 'MyDifferentName',
attributes: {'extra_attribute': 'attribute_value'},
);
}
return defaultViewInfoExtractor(route);
}
var observer = DatadogNavigationObserver(
datadogSdk: DatadogSdk.instance,
viewInfoExtractor: infoExtractor,
);
Automatically track resources
Use the Datadog Tracking HTTP Client package to enable automatic tracking of resources and HTTP calls from your RUM views.
Add the package to your pubspec.yaml
and add the following to your initialization file:
final configuration = DdSdkConfiguration(
// configuration
firstPartyHosts: ['example.com'],
)..enableHttpTracking()
Note: The Datadog Tracking HTTP Client modifies HttpOverrides.global
. If you are using your own custom HttpOverrides
, you may need to inherit from DatadogHttpOverrides
. In this case, you do not need to call enableHttpTracking
. Versions of datadog_tracking_http_client
>= 1.3 check the value of HttpOverrides.current
and use this for client creation, so you only need to make sure to initialize HttpOverrides.global
prior to initializing Datadog.
In order to enable Datadog Distributed Tracing, you must set the DdSdkConfiguration.firstPartyHosts
property in your configuration object to a domain that supports distributed tracing. You can also modify the sampling rate for distributed tracing by setting the tracingSamplingRate
on your RumConfiguration
.
firstPartyHosts
does not allow wildcards, but matches any subdomains for a given domain. For example, api.example.com
matches staging.api.example.com
and prod.api.example.com
, not news.example.com
.
RumConfiguration.tracingSamplingRate
sets a default sampling rate of 20%. If you want all resources requests to generate a full distributed trace, set this value to 100.0
.
Automatically track actions
Use RumUserActionDetector
to track user taps that happen in a given Widget tree:
RumUserActionDetector(
rum: DatadogSdk.instance.rum,
child: Scaffold(
appBar: AppBar(
title: const Text('RUM'),
),
body: // Rest of your application
),
);
RumUserActionDetector
automatically detects tap user actions that occur in its tree and sends them to RUM. It detects interactions with several common Flutter widgets.
For most Button types, the detector looks for a Text
widget child, which it uses for the description of the action. In other cases it looks for a Semantics
object child, or an Icon
with its Icon.semanticsLabel
property set.
Alternatively, you can enclose any Widget tree with a `RumUserActionAnnotation``, which uses the provided description when reporting user actions detected in the child tree, without changing the Semantics of the tree.
Container(
margin: const EdgeInsets.all(8),
child: RumUserActionAnnotation(
description: 'My Image Button',
child: InkWell(
onTap: onTap,
child: Column(
children: [
FadeInImage.memoryNetwork(
placeholder: kTransparentImage,
image: image,
),
Center(
child: Text(
text,
style: theme.textTheme.headlineSmall,
),
)
],
),
),
),
);
Further reading
Additional helpful documentation, links, and articles: