Skip to content

Commit 49d7e5b

Browse files
committed
Merge branch 'main' into release/1.0.0
2 parents f46402e + 186e88c commit 49d7e5b

File tree

23 files changed

+467
-222
lines changed

23 files changed

+467
-222
lines changed

README.md

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
# React-Native Monitoring
22

3-
4-
<div class="alert alert-warning">
5-
This feature is in open beta. Contact <a href="https://docs.datadoghq.com/help/">Support</a> to ask questions or to provide feedback on this feature.
6-
</div>
7-
83
Datadog *Real User Monitoring (RUM)* enables you to visualize and analyze the real-time performance and user journeys of your application’s individual users.
94

105
## Setup
@@ -65,46 +60,24 @@ If user interactions tracking is enabled as in the code example above, the SDK t
6560

6661
Alternatively, you can use the `accessibilityLabel` element property to give the tap action a name; otherwise, the element type is reported. You can check the sample app for usage examples.
6762

68-
## Track view navigation
69-
70-
**Note**: Automatic View tracking relies on the [React Navigation](https://reactnavigation.org/) package (minimum supported version is `react-navigation/[email protected]`). If you use another package to handle navigation in your application, use the manual instrumentation method described below.
63+
### Track view navigation
7164

72-
### Setup
65+
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.
7366

74-
To install with NPM, run:
75-
76-
```sh
77-
npm install @datadog/mobile-react-navigation
78-
```
67+
```js
68+
import { DdSdkReactNative, DdSdkReactNativeConfiguration, DdLogs, DdRum } from '@datadog/mobile-react-native';
7969

80-
To install with Yarn, run:
8170

82-
```sh
83-
yarn add @datadog/mobile-react-navigation
71+
// Start a view with a unique view identifier, a custom view url, and an object to attach additional attributes to the view
72+
DdRum.startView('<view-key>', '/view/url', { 'custom.foo': "something" }, Date.now());
73+
// Stops a previously started view with the same unique view identifier, and an object to attach additional attributes to the view
74+
DdRum.stopView('<view-key>', { 'custom.bar': 42 }, Date.now());
8475
```
8576

86-
### Usage
77+
Use one of Datadog's integrations to automatically track views if you're using the following libraries:
8778

88-
To track changes in navigation as RUM Views, set the `onready` callback of your `NavigationContainer` component:
89-
90-
```js
91-
import * as React from 'react';
92-
import { DdRumReactNavigationTracking } from '@datadog/mobile-react-navigation';
93-
94-
function App() {
95-
const navigationRef = React.useRef(null);
96-
return (
97-
<View>
98-
<NavigationContainer ref={navigationRef} onReady={() => {
99-
DdRumReactNavigationTracking.startTrackingViews(navigationRef.current)
100-
}}>
101-
//
102-
</NavigationContainer>
103-
</View>
104-
);
105-
}
106-
```
107-
**Note**: Only one `NavigationContainer` can be tracked at the time. If you need to track another container, stop tracking previous one first.
79+
- If you use the [`react-native-navigation`][5] library, then add the `@datadog/mobile-react-native-navigation` package and follow the [setup instructions][6].
80+
- If you use the [`react-navigation`][7] library, then add the `@datadog/mobile-react-navigation` package and follow the [setup instructions][8].
10881

10982
## Track custom attributes
11083

@@ -195,9 +168,27 @@ Resource tracking is able to provide the following timings:
195168
* `First Byte` - The time between the scheduled request and the first byte of the response. This includes time for the request preparation on the native level, network latency, and the time it took the server to prepare the response.
196169
* `Download` - The time it took to receive a response.
197170

171+
## Development mode
172+
173+
While in development mode, your application can submit extra events related to the React Native tooling, like code transformation errors, requests to a local development server, etc.
174+
175+
To prevent these events from showing in the dashboard, you can disable errors and resources tracking in dev mode, using the `__DEV__` flag:
176+
177+
```
178+
const config = new DdSdkReactNativeConfiguration(
179+
CLIENT_TOKEN,
180+
ENVIRONMENT,
181+
APPLICATION_ID,
182+
true,
183+
!__DEV__ /* trackResources will be false in DEV mode, true otherwise */,
184+
!__DEV__ /* trackErrors will be false in DEV mode, true otherwise */,
185+
trackingConsent
186+
)
187+
```
188+
198189
## License
199190

200-
[Apache License, v2.0](LICENSE)
191+
[Apache License, v2.0][9]
201192

202193
## Further Reading
203194

@@ -207,3 +198,8 @@ Resource tracking is able to provide the following timings:
207198
[2]: https://raw.githubusercontent.com/DataDog/dd-sdk-reactnative/main/docs/image_reactnative.png
208199
[3]: https://docs.datadoghq.com/account_management/api-app-keys/#api-keys
209200
[4]: https://docs.datadoghq.com/account_management/api-app-keys/#client-tokens
201+
[5]: https://github.com/wix/react-native-navigation
202+
[6]: https://www.npmjs.com/package/@datadog/mobile-react-native-navigation
203+
[7]: https://github.com/react-navigation/react-navigation
204+
[8]: https://www.npmjs.com/package/@datadog/mobile-react-navigation
205+
[9]: https://github.com/DataDog/dd-sdk-reactnative/blob/main/LICENSE

example/ios/Podfile.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
PODS:
22
- boost-for-react-native (1.63.0)
3-
- DatadogSDK (1.7.0-beta3):
3+
- DatadogSDK (1.8.0-beta1):
44
- Kronos (~> 4.2)
5-
- DatadogSDKBridge (0.4.6):
6-
- DatadogSDK (~> 1.7.0-beta3)
5+
- DatadogSDKBridge (0.4.7):
6+
- DatadogSDK (~> 1.8.0-beta1)
77
- DatadogSDKReactNative (1.0.0-rc2):
8-
- DatadogSDKBridge (~> 0.4.6)
8+
- DatadogSDKBridge (~> 0.4.7)
99
- React-Core
1010
- DoubleConversion (1.1.6)
1111
- FBLazyVector (0.63.4)
@@ -393,9 +393,9 @@ EXTERNAL SOURCES:
393393

394394
SPEC CHECKSUMS:
395395
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
396-
DatadogSDK: 82aa63377d806379ad6b149e3a62b2e54e759ca3
397-
DatadogSDKBridge: 15cf2a86b854c53026584a8c2ce5e350e237358f
398-
DatadogSDKReactNative: eea7171abcf614e43005e61e65c84cb0c8df5f54
396+
DatadogSDK: 35cbc8a159ae74ae9318ad157d1e5bc2a9ba23f9
397+
DatadogSDKBridge: 17638afd49b8a5a2ee98533fd001f18c558469cb
398+
DatadogSDKReactNative: 1f66a3a695e1c3e3268ffd51886f5d9264472511
399399
DoubleConversion: cde416483dac037923206447da6e1454df403714
400400
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
401401
FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
@@ -433,4 +433,4 @@ SPEC CHECKSUMS:
433433

434434
PODFILE CHECKSUM: 0622c0089241056d28245084d28a6d85c4b68d8e
435435

436-
COCOAPODS: 1.10.2
436+
COCOAPODS: 1.11.2

example/src/App.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import MainScreen from './screens/MainScreen';
55
import AboutScreen from './screens/AboutScreen';
66
import style from './screens/styles';
77
import { navigationRef } from './NavigationRoot';
8-
import { DdRumReactNavigationTracking } from '@datadog/mobile-react-navigation';
8+
import { DdRumReactNavigationTracking, ViewNamePredicate } from '@datadog/mobile-react-navigation';
9+
import { Route } from "@react-navigation/native";
910

1011
const Tab = createBottomTabNavigator();
1112

13+
const viewPredicate: ViewNamePredicate = function customViewNamePredicate(route: Route<string, any | undefined>, trackedName: string) {
14+
return "Custom RN " + trackedName;
15+
}
16+
1217
export default function App() {
1318
return (
1419
<NavigationContainer ref={navigationRef} onReady={() => {
15-
DdRumReactNavigationTracking.startTrackingViews(navigationRef.current)
20+
DdRumReactNavigationTracking.startTrackingViews(navigationRef.current, viewPredicate)
1621
}}>
1722
<Tab.Navigator tabBarOptions={{
1823
labelStyle: style.tabLabelStyle,

example/src/WixApp.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import React from 'react';
22
import { View, Text, Button } from 'react-native';
3-
import { Navigation } from 'react-native-navigation';
3+
import { ComponentDidAppearEvent, Navigation } from 'react-native-navigation';
44
import MainScreen from './screens/MainScreen';
55
import AboutScreen from './screens/AboutScreen';
6-
import { DdRumReactNativeNavigationTracking } from '@datadog/mobile-react-native-navigation';
6+
import { DdRumReactNativeNavigationTracking, ViewNamePredicate } from '@datadog/mobile-react-native-navigation';
77

88

99
import styles from './screens/styles';
1010

11+
const viewPredicate: ViewNamePredicate = function customViewNamePredicate(_event: ComponentDidAppearEvent, trackedName: string) {
12+
return "Custom RNN " + trackedName;
13+
}
14+
15+
1116
function startReactNativeNavigation() {
12-
DdRumReactNativeNavigationTracking.startTracking();
17+
DdRumReactNativeNavigationTracking.startTracking(viewPredicate);
1318
registerScreens();
1419
Navigation.events().registerAppLaunchedListener(async () => {
1520
Navigation.setRoot({

example/src/ddUtils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function initializeDatadog(trackingConsent: TrackingConsent) {
2121
)
2222
config.nativeCrashReportEnabled = true
2323
config.sampleRate = 100
24+
config.serviceName = "com.datadoghq.reactnative.sample"
2425

2526
DdSdkReactNative.initialize(config).then(() => {
2627
DdLogs.info('The RN Sdk was properly initialized')

packages/core/DatadogSDKReactNative.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
1717
s.source_files = "ios/Sources/*.{h,m,mm,swift}"
1818

1919
s.dependency "React-Core"
20-
s.dependency "DatadogSDKBridge", "~> 0.4.6"
20+
s.dependency "DatadogSDKBridge", "~> 0.4.7"
2121

2222
s.test_spec 'Tests' do |test_spec|
2323
test_spec.source_files = 'ios/Tests/*.swift'

packages/core/README.md

Lines changed: 4 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ const config = new DdSdkReactNativeConfiguration(
4242
true, // track XHR Resources
4343
true // track Errors
4444
)
45-
// Optional: Select your Datadog website (one of "US", "EU" or "GOV")
46-
config.site = "US"
45+
// Optional: Select your Datadog website (one of "US1", "US3", "US5", EU1", or "US1_FED"). Default is "US1".
46+
config.site = "US1"
4747
// Optional: enable or disable native crash reports
4848
config.nativeCrashReportEnabled = true
4949
// Optional: sample RUM sessions (here, 80% of session will be sent to Datadog. Default = 100%)
5050
config.sampleRate = 80
51+
// Optional: set the reported service name (by default, it'll use the package name / bundleIdentifier of your Android / iOS app respectively)
52+
config.serviceName = "com.example.reactnative"
5153

5254
await DdSdkReactNative.initialize(config)
5355

@@ -69,120 +71,3 @@ DdRum.startView('<view-key>', '/view/url', Date.now(), { 'custom.foo': "somethin
6971
DdRum.stopView('<view-key>', Date.now(), { 'custom.bar': 42 });
7072
```
7173

72-
## Track custom attributes
73-
74-
You can attach user information to all RUM events to get more detailed information from your RUM sessions.
75-
76-
### User information
77-
78-
For user-specific information, use the following code wherever you want in your app (after the SDK has been initialized). The `id`, `name`, and `email` attributes are built into Datadog, and you can add other attributes that makes sense for your app.
79-
80-
```js
81-
import { DdSdkReactNative } from '@datadog/mobile-react-native';
82-
83-
DdSdkReactNative.setUser({
84-
id: "1337",
85-
name: "John Smith",
86-
email: "[email protected]",
87-
type: "premium"
88-
})
89-
```
90-
91-
### Global attributes
92-
93-
You can also keep global attributes to track information about a specific session, such as A/B testing configuration, ad campaign origin, or cart status.
94-
95-
```js
96-
import { DdSdkReactNative } from '@datadog/mobile-react-native';
97-
98-
DdSdkReactNative.setAttributes({
99-
profile_mode: "wall",
100-
chat_enabled: true,
101-
campaign_origin: "example_ad_network"
102-
})
103-
```
104-
105-
## Manual instrumentation
106-
107-
If automatic instrumentation doesn't suit your needs, you can manually create any type of events:
108-
109-
### RUM Events
110-
111-
In addition to manually creating Views (as mentioned above), you can also create custom Actions, Resources and Errors
112-
113-
```js
114-
import { DdRum } from '@datadog/mobile-react-native';
115-
116-
// Track RUM Views manually
117-
DdRum.startView('<view-key>', 'View Url', {}, Date.now());
118-
//
119-
DdRum.stopView('<view-key>', { 'custom': 42 }, Date.now());
120-
121-
// Track RUM Actions manually
122-
DdRum.addAction('TAP', 'button name', {}, Date.now());
123-
// or in case of continuous action
124-
DdRum.startAction('TAP', 'button name', {}, Date.now());
125-
// to stop action above
126-
DdRum.stopAction({}, Date.now());
127-
128-
// Add custom timings
129-
DdRum.addTiming('<timing-name>');
130-
131-
// Track RUM Errors manually
132-
DdRum.addError('<message>', 'source', '<stacktrace>', {}, Date.now());
133-
134-
// Track RUM Resource manually
135-
DdRum.startResource('<res-key>', 'GET', 'http://www.example.com/api/v1/test', {}, Date.now());
136-
//
137-
DdRum.stopResource('<res-key>', 200, 'xhr', {}, Date.now());
138-
```
139-
140-
### Logs
141-
142-
You can send custom log messages from anywhere in your application using the following commands:
143-
144-
```js
145-
import { DdLogs } from '@datadog/mobile-react-native';
146-
147-
// Send logs (use the debug, info, warn or error methods) with object to attach additional attributes to the log
148-
DdLogs.debug("Lorem ipsum dolor sit amet…", { 'custom': 42 });
149-
DdLogs.info("Lorem ipsum dolor sit amet…", { 'custom': 42 });
150-
DdLogs.warn("Lorem ipsum dolor sit amet…", { 'custom': 42 });
151-
DdLogs.error("Lorem ipsum dolor sit amet…", { 'custom': 42 });
152-
```
153-
154-
### Spans
155-
156-
You can use spans to trace local computation performance, using the following commands:
157-
158-
```js
159-
import { DdTrace } from '@datadog/mobile-react-native';
160-
161-
// Start a span with an object to attach additional attributes to the span
162-
const spanId = await DdTrace.startSpan("<operation-name>", { 'custom.x': 42 }, Date.now());
163-
164-
// perform some computation...
165-
166-
// Stop the previously started span
167-
DdTrace.finishSpan(spanId, { 'custom.y': 23 }, Date.now());
168-
```
169-
170-
## Resource timings
171-
172-
Resource tracking is able to provide the following timings:
173-
174-
* `First Byte` - The time between the scheduled request and the first byte of the response. This includes time for the request preparation on the native level, network latency, and the time it took the server to prepare the response.
175-
* `Download` - The time it took to receive a response.
176-
177-
## License
178-
179-
[Apache License, v2.0](LICENSE)
180-
181-
## Further Reading
182-
183-
{{< partial name="whats-next/whats-next.html" >}}
184-
185-
[1]: https://app.datadoghq.com/rum/application/create
186-
[2]: https://raw.githubusercontent.com/DataDog/dd-sdk-reactnative/main/docs/image_reactnative.png
187-
[3]: https://docs.datadoghq.com/account_management/api-app-keys/#api-keys
188-
[4]: https://docs.datadoghq.com/account_management/api-app-keys/#client-tokens

packages/core/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ dependencies {
129129
// noinspection GradleDynamicVersion
130130
api 'com.facebook.react:react-native:+'
131131

132-
implementation "com.datadoghq:dd-bridge-android:0.4.4"
132+
implementation "com.datadoghq:dd-bridge-android:0.4.6"
133133

134134
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
135135
}

packages/core/ios/Sources/QueueHolder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
import Foundation
88

9-
internal let sharedQueue = dispatch_queue_serial_t(label: "dd-react-native-sdk")
9+
internal let sharedQueue = DispatchQueue(label: "dd-react-native-sdk")

packages/core/ios/Tests/ModulesTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
import XCTest
8-
@testable import dd_sdk_reactnative
8+
@testable import DatadogSDKReactNative
99
@testable import React.RCTModuleData
1010

1111
// Since RN tooling does the modules linking automatically, it doesn't include testspecs
1212
// To do that modify node_modules/@react-native-community/cli-platform-ios/native_modules.rb#L90 to:
1313
//
14-
// if spec.name == "dd-sdk-reactnative"
14+
// if spec.name == "DatadogSDKReactNative"
1515
// pod spec.name, :path => relative_path.to_path, :testspecs => ['Tests']
1616
// else
1717
// pod spec.name, :path => relative_path.to_path

0 commit comments

Comments
 (0)