React-Native Monitoring
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
To install with NPM, run:
npm install @datadog/mobile-react-native
To install with Yarn, run:
yarn add @datadog/mobile-react-native
Minimum React Native version: SDK supports React Native version 0.63.4 or higher. Compatibility with older versions is not guaranteed out of the box.
Versions 1.0.0-rc5
and higher require you to have compileSdkVersion = 31
in the Android application setup, which implies that you should use Build Tools version 31, Android Gradle Plugin version 7, and Gradle version 7 or higher. To modify the versions, change the values in the buildscript.ext
block of your application's top-level build.gradle
file. Datadog recommends using React Native version 0.67 or higher.
Specify application details in UI
- In the Datadog app, select UX Monitoring > RUM Applications > New Application.
- Choose
react-native
as your Application Type. - Provide a new application name to generate a unique Datadog application ID and client token.
To ensure the safety of your data, you must use a client token. You cannot use only Datadog API keys to configure the @datadog/mobile-react-native
library, because they would be exposed client-side. For more information about setting up a client token, see the Client Token documentation.
Initialize the library with application context
import {
DatadogProvider,
DatadogProviderConfiguration
} from '@datadog/mobile-react-native';
const datadogConfiguration = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
'<RUM_APPLICATION_ID>',
true,
true,
true
);
datadogConfiguration.site = 'US1';
datadogConfiguration.nativeCrashReportEnabled = true;
datadogConfiguration.sessionSamplingRate = 80;
datadogConfiguration.resourceTracingSamplingRate = 80;
datadogConfiguration.firstPartyHosts = ['example.com'];
datadogConfiguration.serviceName = 'com.example.reactnative';
datadogConfiguration.verbosity = SdkVerbosity.WARN;
export default function App() {
return (
<DatadogProvider configuration={datadogConfiguration}>
<Navigation />
</DatadogProvider>
);
}
Track view navigation
Because React Native offers a wide range of libraries to create screen navigation, by default only manual View tracking is supported. You can manually start and stop a View using the following startView()
and stopView
methods.
import {
DdSdkReactNative,
DdSdkReactNativeConfiguration,
DdLogs,
DdRum
} from '@datadog/mobile-react-native';
DdRum.startView('ViewKey', 'ViewName', Date.now(), {
'custom.foo': 'something'
});
DdRum.stopView('ViewKey', Date.now(), { 'custom.bar': 42 });
Data Storage
Android
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
tempers with the linux kernel, the stored data might become readable.
iOS
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.