![]() |
VOOZH | about |
Send logs to Datadog from your React Native Mobile applications with Datadog’s dd-sdk-reactnative client-side logging library and leverage the following features:
context and extra custom attributes to each log sent.@datadog/mobile-react-native packageTo install with NPM, run:
npm install @datadog/mobile-react-native
To install with Yarn, run:
yarn add @datadog/mobile-react-native
Then install the added pod:
(cd ios && pod install)
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.
dd-sdk-reactnative library, as they would be exposed client-side in the mobile application. For more information about setting up a client token, see the client token documentation.import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'US1',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'US3',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'US5',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'EU1',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'US1_FED',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'US2_FED',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'AP1',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
import { DatadogProviderConfiguration } from '@datadog/mobile-react-native';
const config = new DatadogProviderConfiguration(
'<CLIENT_TOKEN>',
'<ENVIRONMENT_NAME>',
trackingConsent,
{
site: 'AP2',
rumConfiguration: {
applicationId: '<APPLICATION_ID>', // RUM Application ID
trackInteractions: true, // Track user interactions (set to false if using Error Tracking only)
trackResources: true, // Track XHR resources (set to false if using Error Tracking only)
trackErrors: true, // Track errors
},
logsConfiguration: {}, // Enable Logs
traceConfiguration: {} // Enable Traces
}
);
Import the React Native logger:
import { DdLogs } from '@datadog/mobile-react-native';
Send a custom log entry directly to Datadog with one of the following functions:
DdLogs.debug('A debug message.', { customAttribute: 'something' })
DdLogs.info('Some relevant information ?', { customCount: 42 })
DdLogs.warn('An important warning…', {})
DdLogs.error('An error was met!', {})
Note: All logging methods can have a context object with custom attributes.
All the logs are first stored on the local device in batches. Each batch follows the intake specification. They are sent as soon as network is available, and the battery is high enough to ensure the Datadog SDK does not impact the end user’s experience. If the network is not available while your application is in the foreground, or if an upload of data fails, the batch is kept until it can be sent successfully.
This means that even if users open your application while being offline, no data will be lost.
The data on disk will automatically be discarded if it gets too old to ensure the SDK doesn’t use too much disk space.
Starting from v2.4.2, you can add a custom fingerprint to the error logs by using the fingerprint argument:
export type LogWithErrorArguments = [
message: string,
errorKind?: string,
errorMessage?: string,
stacktrace?: string,
context?: object,
fingerprint?: string
];
Additional helpful documentation, links, and articles:
| |