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
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
.
Alternatively, 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
.
To rename your views or supply custom paths, provide 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
.
Further reading
Additional helpful documentation, links, and articles: