@datadog/mobile-react-native 1.5.2 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DatadogSDKReactNative.podspec +2 -2
- package/android/build.gradle +2 -1
- package/android/gradle.properties +1 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +4 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +6 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdLogs.kt +162 -6
- package/android/src/main/kotlin/com/datadog/reactnative/DdRum.kt +25 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +32 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +11 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +10 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +242 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +27 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +126 -30
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +19 -1
- package/android/src/test/kotlin/com/datadog/tools/unit/GenericAssert.kt +2 -2
- package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +18 -1
- package/ios/Sources/Attributes.swift +7 -0
- package/ios/Sources/DdLogs.m +31 -0
- package/ios/Sources/DdLogs.swift +84 -4
- package/ios/Sources/DdRum.m +8 -0
- package/ios/Sources/DdRum.swift +17 -0
- package/ios/Sources/DdSdk.swift +40 -0
- package/ios/Sources/DdSdkConfiguration.swift +19 -1
- package/ios/Sources/RNDdSdkConfiguration.swift +11 -1
- package/lib/commonjs/DdSdkReactNative.js +6 -2
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +45 -2
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +6 -2
- package/lib/commonjs/InternalLog.js.map +1 -1
- package/lib/commonjs/errorUtils.js +20 -1
- package/lib/commonjs/errorUtils.js.map +1 -1
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/logs/DdLogs.js +102 -11
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/logs/eventMapper.js.map +1 -1
- package/lib/commonjs/nativeModulesTypes.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +14 -0
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +62 -46
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
- package/lib/commonjs/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
- package/lib/commonjs/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
- package/lib/commonjs/rum/types.js.map +1 -1
- package/lib/commonjs/types.js +4 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +6 -2
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +42 -1
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +2 -1
- package/lib/module/InternalLog.js.map +1 -1
- package/lib/module/errorUtils.js +15 -0
- package/lib/module/errorUtils.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/logs/DdLogs.js +103 -12
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/logs/eventMapper.js.map +1 -1
- package/lib/module/nativeModulesTypes.js.map +1 -1
- package/lib/module/rum/DdRum.js +12 -0
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +63 -46
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js +2 -2
- package/lib/module/rum/instrumentation/interactionTracking/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js +9 -1
- package/lib/module/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.js.map +1 -1
- package/lib/module/rum/types.js.map +1 -1
- package/lib/module/types.js +4 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +47 -0
- package/lib/typescript/InternalLog.d.ts +1 -0
- package/lib/typescript/errorUtils.d.ts +2 -0
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/logs/DdLogs.d.ts +13 -5
- package/lib/typescript/logs/eventMapper.d.ts +5 -5
- package/lib/typescript/logs/types.d.ts +34 -8
- package/lib/typescript/nativeModulesTypes.d.ts +51 -4
- package/lib/typescript/rum/DdRum.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +3 -2
- package/lib/typescript/rum/instrumentation/interactionTracking/DdEventsInterceptor.d.ts +1 -1
- package/lib/typescript/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.d.ts +5 -2
- package/lib/typescript/rum/types.d.ts +4 -0
- package/lib/typescript/types.d.ts +8 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +9 -1
- package/src/DdSdkReactNativeConfiguration.tsx +56 -1
- package/src/InternalLog.tsx +3 -1
- package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +20 -3
- package/src/__tests__/errorUtils.test.ts +49 -0
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +14 -14
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +474 -109
- package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +18 -0
- package/src/errorUtils.ts +15 -0
- package/src/index.tsx +6 -2
- package/src/logs/DdLogs.ts +166 -16
- package/src/logs/__tests__/DdLogs.test.ts +169 -0
- package/src/logs/__tests__/eventMapper.test.ts +34 -0
- package/src/logs/eventMapper.ts +15 -4
- package/src/logs/types.ts +36 -8
- package/src/nativeModulesTypes.ts +81 -4
- package/src/rum/DdRum.ts +17 -0
- package/src/rum/__tests__/DdRum.test.ts +12 -27
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +44 -10
- package/src/rum/instrumentation/interactionTracking/DdEventsInterceptor.tsx +7 -4
- package/src/rum/instrumentation/interactionTracking/ShallowObjectEqualityChecker.ts +11 -3
- package/src/rum/types.ts +5 -0
- package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +5 -0
- package/src/types.tsx +5 -0
- package/src/version.ts +1 -1
|
@@ -4,21 +4,17 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import { DdRumErrorTracking } from '../../../rum/instrumentation/DdRumErrorTracking';
|
|
7
|
+
import { NativeModules } from 'react-native';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
import type {
|
|
10
|
+
DdNativeLogsType,
|
|
11
|
+
DdNativeRumType
|
|
12
|
+
} from '../../../nativeModulesTypes';
|
|
13
|
+
import { DdRumErrorTracking } from '../../../rum/instrumentation/DdRumErrorTracking';
|
|
14
|
+
import { BufferSingleton } from '../../../sdk/DatadogProvider/Buffer/BufferSingleton';
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
DdRum: {
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
16
|
-
addError: jest.fn().mockImplementation(() => {
|
|
17
|
-
return Promise.resolve();
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
});
|
|
16
|
+
const DdRum = NativeModules.DdRum as DdNativeRumType;
|
|
17
|
+
const DdLogs = NativeModules.DdLogs as DdNativeLogsType;
|
|
22
18
|
|
|
23
19
|
let baseErrorHandlerCalled = false;
|
|
24
20
|
const baseErrorHandler = (error: any, isFatal?: boolean) => {
|
|
@@ -36,7 +32,8 @@ const flushPromises = () =>
|
|
|
36
32
|
new Promise(jest.requireActual('timers').setImmediate);
|
|
37
33
|
|
|
38
34
|
beforeEach(() => {
|
|
39
|
-
|
|
35
|
+
jest.clearAllMocks();
|
|
36
|
+
BufferSingleton.onInitialization();
|
|
40
37
|
baseErrorHandlerCalled = false;
|
|
41
38
|
originalErrorHandler = ErrorUtils.getGlobalHandler();
|
|
42
39
|
ErrorUtils.setGlobalHandler(baseErrorHandler);
|
|
@@ -64,16 +61,32 @@ it('M intercept and send a RUM event W onGlobalError() {no message}', async () =
|
|
|
64
61
|
await flushPromises();
|
|
65
62
|
|
|
66
63
|
// THEN
|
|
67
|
-
expect(DdRum.addError
|
|
68
|
-
expect(DdRum.addError
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
'doSomething() at ./path/to/file.js:67:3'
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
66
|
+
'[object Object]',
|
|
67
|
+
'SOURCE',
|
|
68
|
+
'doSomething() at ./path/to/file.js:67:3',
|
|
69
|
+
{
|
|
70
|
+
'_dd.error.raw': error,
|
|
71
|
+
'_dd.error.is_crash': is_fatal,
|
|
72
|
+
'_dd.error.source_type': 'react-native'
|
|
73
|
+
},
|
|
74
|
+
expect.any(Number)
|
|
75
|
+
);
|
|
76
76
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
77
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
78
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
79
|
+
'[object Object]',
|
|
80
|
+
'Error',
|
|
81
|
+
'[object Object]',
|
|
82
|
+
'doSomething() at ./path/to/file.js:67:3',
|
|
83
|
+
{
|
|
84
|
+
'_dd.error.raw': error,
|
|
85
|
+
'_dd.error.is_crash': is_fatal,
|
|
86
|
+
'_dd.error.source_type': 'react-native',
|
|
87
|
+
'_dd.error_log.is_crash': true
|
|
88
|
+
}
|
|
89
|
+
);
|
|
77
90
|
});
|
|
78
91
|
|
|
79
92
|
it('M intercept and send a RUM event W onGlobalError() {empty stack trace}', async () => {
|
|
@@ -89,14 +102,32 @@ it('M intercept and send a RUM event W onGlobalError() {empty stack trace}', asy
|
|
|
89
102
|
await flushPromises();
|
|
90
103
|
|
|
91
104
|
// THEN
|
|
92
|
-
expect(DdRum.addError
|
|
93
|
-
expect(DdRum.addError
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
107
|
+
'Something bad happened',
|
|
108
|
+
'SOURCE',
|
|
109
|
+
'',
|
|
110
|
+
{
|
|
111
|
+
'_dd.error.raw': error,
|
|
112
|
+
'_dd.error.is_crash': is_fatal,
|
|
113
|
+
'_dd.error.source_type': 'react-native'
|
|
114
|
+
},
|
|
115
|
+
expect.any(Number)
|
|
116
|
+
);
|
|
99
117
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
118
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
119
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
120
|
+
'Something bad happened',
|
|
121
|
+
'Error',
|
|
122
|
+
'Something bad happened',
|
|
123
|
+
'',
|
|
124
|
+
{
|
|
125
|
+
'_dd.error.raw': error,
|
|
126
|
+
'_dd.error.is_crash': is_fatal,
|
|
127
|
+
'_dd.error.source_type': 'react-native',
|
|
128
|
+
'_dd.error_log.is_crash': true
|
|
129
|
+
}
|
|
130
|
+
);
|
|
100
131
|
});
|
|
101
132
|
|
|
102
133
|
it('M intercept and send a RUM event W onGlobalError() {Error object}', async () => {
|
|
@@ -110,19 +141,81 @@ it('M intercept and send a RUM event W onGlobalError() {Error object}', async ()
|
|
|
110
141
|
await flushPromises();
|
|
111
142
|
|
|
112
143
|
// THEN
|
|
113
|
-
expect(DdRum.addError
|
|
114
|
-
expect(DdRum.addError
|
|
115
|
-
|
|
144
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
145
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
146
|
+
'Something bad happened',
|
|
147
|
+
'SOURCE',
|
|
148
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
149
|
+
{
|
|
150
|
+
'_dd.error.raw': error,
|
|
151
|
+
'_dd.error.is_crash': is_fatal,
|
|
152
|
+
'_dd.error.source_type': 'react-native'
|
|
153
|
+
},
|
|
154
|
+
expect.any(Number)
|
|
155
|
+
);
|
|
116
156
|
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
117
|
-
'
|
|
157
|
+
'/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx'
|
|
158
|
+
);
|
|
159
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
160
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
161
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
162
|
+
'Something bad happened',
|
|
163
|
+
'Error',
|
|
164
|
+
'Something bad happened',
|
|
165
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
166
|
+
{
|
|
167
|
+
'_dd.error.raw': error,
|
|
168
|
+
'_dd.error.is_crash': is_fatal,
|
|
169
|
+
'_dd.error.source_type': 'react-native',
|
|
170
|
+
'_dd.error_log.is_crash': true
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('M intercept and send a RUM event W onGlobalError() {CustomError object}', async () => {
|
|
176
|
+
// GIVEN
|
|
177
|
+
class CustomError extends Error {
|
|
178
|
+
name = 'CustomError';
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
DdRumErrorTracking.startTracking();
|
|
182
|
+
const is_fatal = Math.random() < 0.5;
|
|
183
|
+
const error = new CustomError('Something bad happened');
|
|
184
|
+
|
|
185
|
+
// WHEN
|
|
186
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
187
|
+
await flushPromises();
|
|
188
|
+
|
|
189
|
+
// THEN
|
|
190
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
191
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
192
|
+
'Something bad happened',
|
|
193
|
+
'SOURCE',
|
|
194
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
195
|
+
{
|
|
196
|
+
'_dd.error.raw': error,
|
|
197
|
+
'_dd.error.is_crash': is_fatal,
|
|
198
|
+
'_dd.error.source_type': 'react-native'
|
|
199
|
+
},
|
|
200
|
+
expect.any(Number)
|
|
118
201
|
);
|
|
119
202
|
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
120
203
|
'/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx'
|
|
121
204
|
);
|
|
122
|
-
const attributes = DdRum.addError.mock.calls[0][3];
|
|
123
|
-
expect(attributes['_dd.error.raw']).toStrictEqual(error);
|
|
124
|
-
expect(attributes['_dd.error.is_crash']).toStrictEqual(is_fatal);
|
|
125
205
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
206
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
207
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
208
|
+
'Something bad happened',
|
|
209
|
+
'CustomError',
|
|
210
|
+
'Something bad happened',
|
|
211
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
212
|
+
{
|
|
213
|
+
'_dd.error.raw': error,
|
|
214
|
+
'_dd.error.is_crash': is_fatal,
|
|
215
|
+
'_dd.error.source_type': 'react-native',
|
|
216
|
+
'_dd.error_log.is_crash': true
|
|
217
|
+
}
|
|
218
|
+
);
|
|
126
219
|
});
|
|
127
220
|
|
|
128
221
|
it('M intercept and send a RUM event W onGlobalError() {with source file info}', async () => {
|
|
@@ -141,16 +234,32 @@ it('M intercept and send a RUM event W onGlobalError() {with source file info}',
|
|
|
141
234
|
await flushPromises();
|
|
142
235
|
|
|
143
236
|
// THEN
|
|
144
|
-
expect(DdRum.addError
|
|
145
|
-
expect(DdRum.addError
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
'at ./path/to/file.js:1038:57'
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
237
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
238
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
239
|
+
'Something bad happened',
|
|
240
|
+
'SOURCE',
|
|
241
|
+
'at ./path/to/file.js:1038:57',
|
|
242
|
+
{
|
|
243
|
+
'_dd.error.raw': error,
|
|
244
|
+
'_dd.error.is_crash': is_fatal,
|
|
245
|
+
'_dd.error.source_type': 'react-native'
|
|
246
|
+
},
|
|
247
|
+
expect.any(Number)
|
|
248
|
+
);
|
|
153
249
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
250
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
251
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
252
|
+
'Something bad happened',
|
|
253
|
+
'Error',
|
|
254
|
+
'Something bad happened',
|
|
255
|
+
'at ./path/to/file.js:1038:57',
|
|
256
|
+
{
|
|
257
|
+
'_dd.error.raw': error,
|
|
258
|
+
'_dd.error.is_crash': is_fatal,
|
|
259
|
+
'_dd.error.source_type': 'react-native',
|
|
260
|
+
'_dd.error_log.is_crash': true
|
|
261
|
+
}
|
|
262
|
+
);
|
|
154
263
|
});
|
|
155
264
|
|
|
156
265
|
it('M intercept and send a RUM event W onGlobalError() {with component stack}', async () => {
|
|
@@ -171,16 +280,32 @@ it('M intercept and send a RUM event W onGlobalError() {with component stack}',
|
|
|
171
280
|
await flushPromises();
|
|
172
281
|
|
|
173
282
|
// THEN
|
|
174
|
-
expect(DdRum.addError
|
|
175
|
-
expect(DdRum.addError
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
283
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
284
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
285
|
+
'Something bad happened',
|
|
286
|
+
'SOURCE',
|
|
287
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
288
|
+
{
|
|
289
|
+
'_dd.error.raw': error,
|
|
290
|
+
'_dd.error.is_crash': is_fatal,
|
|
291
|
+
'_dd.error.source_type': 'react-native'
|
|
292
|
+
},
|
|
293
|
+
expect.any(Number)
|
|
294
|
+
);
|
|
183
295
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
296
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
297
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
298
|
+
'Something bad happened',
|
|
299
|
+
'Error',
|
|
300
|
+
'Something bad happened',
|
|
301
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
302
|
+
{
|
|
303
|
+
'_dd.error.raw': error,
|
|
304
|
+
'_dd.error.is_crash': is_fatal,
|
|
305
|
+
'_dd.error.source_type': 'react-native',
|
|
306
|
+
'_dd.error_log.is_crash': true
|
|
307
|
+
}
|
|
308
|
+
);
|
|
184
309
|
});
|
|
185
310
|
|
|
186
311
|
it('M intercept and send a RUM event W onGlobalError() {with stack}', async () => {
|
|
@@ -201,16 +326,32 @@ it('M intercept and send a RUM event W onGlobalError() {with stack}', async () =
|
|
|
201
326
|
await flushPromises();
|
|
202
327
|
|
|
203
328
|
// THEN
|
|
204
|
-
expect(DdRum.addError
|
|
205
|
-
expect(DdRum.addError
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
329
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
330
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
331
|
+
'Something bad happened',
|
|
332
|
+
'SOURCE',
|
|
333
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
334
|
+
{
|
|
335
|
+
'_dd.error.raw': error,
|
|
336
|
+
'_dd.error.is_crash': is_fatal,
|
|
337
|
+
'_dd.error.source_type': 'react-native'
|
|
338
|
+
},
|
|
339
|
+
expect.any(Number)
|
|
340
|
+
);
|
|
213
341
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
342
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
343
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
344
|
+
'Something bad happened',
|
|
345
|
+
'Error',
|
|
346
|
+
'Something bad happened',
|
|
347
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
348
|
+
{
|
|
349
|
+
'_dd.error.raw': error,
|
|
350
|
+
'_dd.error.is_crash': is_fatal,
|
|
351
|
+
'_dd.error.source_type': 'react-native',
|
|
352
|
+
'_dd.error_log.is_crash': true
|
|
353
|
+
}
|
|
354
|
+
);
|
|
214
355
|
});
|
|
215
356
|
|
|
216
357
|
it('M intercept and send a RUM event W onGlobalError() {with stacktrace}', async () => {
|
|
@@ -231,16 +372,33 @@ it('M intercept and send a RUM event W onGlobalError() {with stacktrace}', async
|
|
|
231
372
|
await flushPromises();
|
|
232
373
|
|
|
233
374
|
// THEN
|
|
234
|
-
expect(DdRum.addError
|
|
235
|
-
expect(DdRum.addError
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
375
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
376
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
377
|
+
'Something bad happened',
|
|
378
|
+
'SOURCE',
|
|
379
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
380
|
+
{
|
|
381
|
+
'_dd.error.raw': error,
|
|
382
|
+
'_dd.error.is_crash': is_fatal,
|
|
383
|
+
'_dd.error.source_type': 'react-native'
|
|
384
|
+
},
|
|
385
|
+
expect.any(Number)
|
|
386
|
+
);
|
|
243
387
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
388
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
389
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
390
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
391
|
+
'Something bad happened',
|
|
392
|
+
'Error',
|
|
393
|
+
'Something bad happened',
|
|
394
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
395
|
+
{
|
|
396
|
+
'_dd.error.raw': error,
|
|
397
|
+
'_dd.error.is_crash': is_fatal,
|
|
398
|
+
'_dd.error.source_type': 'react-native',
|
|
399
|
+
'_dd.error_log.is_crash': true
|
|
400
|
+
}
|
|
401
|
+
);
|
|
244
402
|
});
|
|
245
403
|
|
|
246
404
|
it('M not report error in console handler W onGlobalError() {with console reporting handler}', async () => {
|
|
@@ -266,17 +424,34 @@ it('M not report error in console handler W onGlobalError() {with console report
|
|
|
266
424
|
await flushPromises();
|
|
267
425
|
|
|
268
426
|
// THEN
|
|
269
|
-
expect(DdRum.addError
|
|
270
|
-
expect(DdRum.addError
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
427
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
428
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
429
|
+
'Something bad happened',
|
|
430
|
+
'SOURCE',
|
|
431
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
432
|
+
{
|
|
433
|
+
'_dd.error.raw': error,
|
|
434
|
+
'_dd.error.is_crash': is_fatal,
|
|
435
|
+
'_dd.error.source_type': 'react-native'
|
|
436
|
+
},
|
|
437
|
+
expect.any(Number)
|
|
438
|
+
);
|
|
278
439
|
expect(consoleReportingErrorHandler).toBeCalledTimes(1);
|
|
279
440
|
expect(baseConsoleErrorCalled).toStrictEqual(false);
|
|
441
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
442
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
443
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
444
|
+
'Something bad happened',
|
|
445
|
+
'Error',
|
|
446
|
+
'Something bad happened',
|
|
447
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
448
|
+
{
|
|
449
|
+
'_dd.error.raw': error,
|
|
450
|
+
'_dd.error.is_crash': is_fatal,
|
|
451
|
+
'_dd.error.source_type': 'react-native',
|
|
452
|
+
'_dd.error_log.is_crash': true
|
|
453
|
+
}
|
|
454
|
+
);
|
|
280
455
|
});
|
|
281
456
|
|
|
282
457
|
it('M intercept and send a RUM event W onConsole() {Error with source file info}', async () => {
|
|
@@ -295,16 +470,28 @@ it('M intercept and send a RUM event W onConsole() {Error with source file info}
|
|
|
295
470
|
await flushPromises();
|
|
296
471
|
|
|
297
472
|
// THEN
|
|
298
|
-
expect(DdRum.addError
|
|
299
|
-
expect(DdRum.addError
|
|
300
|
-
'Oops I did it again! Something bad happened'
|
|
473
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
474
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
475
|
+
'Oops I did it again! Something bad happened',
|
|
476
|
+
'CONSOLE',
|
|
477
|
+
'at ./path/to/file.js:1038:57',
|
|
478
|
+
{
|
|
479
|
+
'_dd.error.source_type': 'react-native'
|
|
480
|
+
},
|
|
481
|
+
expect.any(Number)
|
|
301
482
|
);
|
|
302
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe('CONSOLE');
|
|
303
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
304
|
-
'at ./path/to/file.js:1038:57'
|
|
305
|
-
);
|
|
306
|
-
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
307
483
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
484
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
485
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
486
|
+
'Oops I did it again! Something bad happened',
|
|
487
|
+
'Error',
|
|
488
|
+
'Oops I did it again! Something bad happened',
|
|
489
|
+
'at ./path/to/file.js:1038:57',
|
|
490
|
+
{
|
|
491
|
+
'_dd.error.source_type': 'react-native',
|
|
492
|
+
'_dd.error_log.is_crash': true
|
|
493
|
+
}
|
|
494
|
+
);
|
|
308
495
|
});
|
|
309
496
|
|
|
310
497
|
it('M intercept and send a RUM event W onConsole() {Error with component stack}', async () => {
|
|
@@ -325,16 +512,28 @@ it('M intercept and send a RUM event W onConsole() {Error with component stack}'
|
|
|
325
512
|
await flushPromises();
|
|
326
513
|
|
|
327
514
|
// THEN
|
|
328
|
-
expect(DdRum.addError
|
|
329
|
-
expect(DdRum.addError
|
|
330
|
-
'Oops I did it again! Something bad happened'
|
|
515
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
516
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
517
|
+
'Oops I did it again! Something bad happened',
|
|
518
|
+
'CONSOLE',
|
|
519
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
520
|
+
{
|
|
521
|
+
'_dd.error.source_type': 'react-native'
|
|
522
|
+
},
|
|
523
|
+
expect.any(Number)
|
|
331
524
|
);
|
|
332
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe('CONSOLE');
|
|
333
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe(
|
|
334
|
-
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1'
|
|
335
|
-
);
|
|
336
|
-
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
337
525
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
526
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
527
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
528
|
+
'Oops I did it again! Something bad happened',
|
|
529
|
+
'Error',
|
|
530
|
+
'Oops I did it again! Something bad happened',
|
|
531
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
532
|
+
{
|
|
533
|
+
'_dd.error.source_type': 'react-native',
|
|
534
|
+
'_dd.error_log.is_crash': true
|
|
535
|
+
}
|
|
536
|
+
);
|
|
338
537
|
});
|
|
339
538
|
|
|
340
539
|
it('M intercept and send a RUM event W onConsole() {message only}', async () => {
|
|
@@ -347,12 +546,69 @@ it('M intercept and send a RUM event W onConsole() {message only}', async () =>
|
|
|
347
546
|
await flushPromises();
|
|
348
547
|
|
|
349
548
|
// THEN
|
|
350
|
-
expect(DdRum.addError
|
|
351
|
-
expect(DdRum.addError
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
549
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
550
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
551
|
+
message,
|
|
552
|
+
'CONSOLE',
|
|
553
|
+
'',
|
|
554
|
+
{
|
|
555
|
+
'_dd.error.source_type': 'react-native'
|
|
556
|
+
},
|
|
557
|
+
expect.any(Number)
|
|
558
|
+
);
|
|
355
559
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
560
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
561
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
562
|
+
'Something bad happened',
|
|
563
|
+
'Error',
|
|
564
|
+
'Something bad happened',
|
|
565
|
+
'',
|
|
566
|
+
{
|
|
567
|
+
'_dd.error.source_type': 'react-native',
|
|
568
|
+
'_dd.error_log.is_crash': true
|
|
569
|
+
}
|
|
570
|
+
);
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it('M intercept and send a RUM event W onConsole() {Error with source file and name}', async () => {
|
|
574
|
+
// GIVEN
|
|
575
|
+
DdRumErrorTracking.startTracking();
|
|
576
|
+
const message = 'Oops I did it again!';
|
|
577
|
+
const error = {
|
|
578
|
+
sourceURL: './path/to/file.js',
|
|
579
|
+
line: 1038,
|
|
580
|
+
column: 57,
|
|
581
|
+
message: 'Something bad happened',
|
|
582
|
+
name: 'CustomConsoleError'
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// WHEN
|
|
586
|
+
DdRumErrorTracking.onConsoleError(message, error);
|
|
587
|
+
await flushPromises();
|
|
588
|
+
|
|
589
|
+
// THEN
|
|
590
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
591
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
592
|
+
'Oops I did it again! Something bad happened',
|
|
593
|
+
'CONSOLE',
|
|
594
|
+
'at ./path/to/file.js:1038:57',
|
|
595
|
+
{
|
|
596
|
+
'_dd.error.source_type': 'react-native'
|
|
597
|
+
},
|
|
598
|
+
expect.any(Number)
|
|
599
|
+
);
|
|
600
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
601
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
602
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
603
|
+
'Oops I did it again! Something bad happened',
|
|
604
|
+
'CustomConsoleError',
|
|
605
|
+
'Oops I did it again! Something bad happened',
|
|
606
|
+
'at ./path/to/file.js:1038:57',
|
|
607
|
+
{
|
|
608
|
+
'_dd.error.source_type': 'react-native',
|
|
609
|
+
'_dd.error_log.is_crash': true
|
|
610
|
+
}
|
|
611
|
+
);
|
|
356
612
|
});
|
|
357
613
|
|
|
358
614
|
describe.each([
|
|
@@ -374,15 +630,124 @@ describe.each([
|
|
|
374
630
|
await flushPromises();
|
|
375
631
|
|
|
376
632
|
// THEN
|
|
377
|
-
|
|
378
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
633
|
+
const errorMessage =
|
|
379
634
|
message === undefined || message === null
|
|
380
635
|
? 'Unknown Error'
|
|
381
|
-
: String(message)
|
|
636
|
+
: String(message);
|
|
637
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
638
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
639
|
+
errorMessage,
|
|
640
|
+
'CONSOLE',
|
|
641
|
+
'',
|
|
642
|
+
{
|
|
643
|
+
'_dd.error.source_type': 'react-native'
|
|
644
|
+
},
|
|
645
|
+
expect.any(Number)
|
|
382
646
|
);
|
|
383
|
-
expect(DdRum.addError.mock.calls[0][1]).toBe('CONSOLE');
|
|
384
|
-
expect(DdRum.addError.mock.calls[0][2]).toBe('');
|
|
385
|
-
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
386
647
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
648
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
649
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
650
|
+
errorMessage,
|
|
651
|
+
'Error',
|
|
652
|
+
errorMessage,
|
|
653
|
+
'',
|
|
654
|
+
{
|
|
655
|
+
'_dd.error.source_type': 'react-native',
|
|
656
|
+
'_dd.error_log.is_crash': true
|
|
657
|
+
}
|
|
658
|
+
);
|
|
387
659
|
});
|
|
388
660
|
});
|
|
661
|
+
|
|
662
|
+
it('M intercept and send a RUM event W on error() {called from RNErrorHandler}', async () => {
|
|
663
|
+
// GIVEN
|
|
664
|
+
const errorHandlerMock = new RNErrorHandlerMock();
|
|
665
|
+
DdRumErrorTracking.startTracking();
|
|
666
|
+
const is_fatal = Math.random() < 0.5;
|
|
667
|
+
const error = new Error('Something bad happened');
|
|
668
|
+
|
|
669
|
+
// WHEN
|
|
670
|
+
errorHandlerMock.onError(error, is_fatal);
|
|
671
|
+
await flushPromises();
|
|
672
|
+
|
|
673
|
+
// THEN
|
|
674
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
675
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
676
|
+
'Something bad happened',
|
|
677
|
+
'SOURCE',
|
|
678
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
679
|
+
{
|
|
680
|
+
'_dd.error.raw': error,
|
|
681
|
+
'_dd.error.is_crash': is_fatal,
|
|
682
|
+
'_dd.error.source_type': 'react-native'
|
|
683
|
+
},
|
|
684
|
+
expect.any(Number)
|
|
685
|
+
);
|
|
686
|
+
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
687
|
+
'/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx'
|
|
688
|
+
);
|
|
689
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
690
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
691
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
692
|
+
'Something bad happened',
|
|
693
|
+
'Error',
|
|
694
|
+
'Something bad happened',
|
|
695
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
696
|
+
{
|
|
697
|
+
'_dd.error.raw': error,
|
|
698
|
+
'_dd.error.is_crash': is_fatal,
|
|
699
|
+
'_dd.error.source_type': 'react-native',
|
|
700
|
+
'_dd.error_log.is_crash': true
|
|
701
|
+
}
|
|
702
|
+
);
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
it('M intercept and send a RUM event W onConsole() {called from RNErrorHandler}', async () => {
|
|
706
|
+
// GIVEN
|
|
707
|
+
const errorHandlerMock = new RNErrorHandlerMock();
|
|
708
|
+
DdRumErrorTracking.startTracking();
|
|
709
|
+
const message = 'Oops I did it again!';
|
|
710
|
+
|
|
711
|
+
// WHEN
|
|
712
|
+
errorHandlerMock.onConsoleError(message);
|
|
713
|
+
await flushPromises();
|
|
714
|
+
|
|
715
|
+
// THEN
|
|
716
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
717
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
718
|
+
'Oops I did it again!',
|
|
719
|
+
'CONSOLE',
|
|
720
|
+
'',
|
|
721
|
+
{
|
|
722
|
+
'_dd.error.source_type': 'react-native'
|
|
723
|
+
},
|
|
724
|
+
expect.any(Number)
|
|
725
|
+
);
|
|
726
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
727
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
728
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
729
|
+
'Oops I did it again!',
|
|
730
|
+
'Error',
|
|
731
|
+
'Oops I did it again!',
|
|
732
|
+
'',
|
|
733
|
+
{
|
|
734
|
+
'_dd.error.source_type': 'react-native',
|
|
735
|
+
'_dd.error_log.is_crash': true
|
|
736
|
+
}
|
|
737
|
+
);
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* This is a mock of the RN error handler class that will call the ErrorUtils.
|
|
742
|
+
* Testing with this catches bugs around `this` references.
|
|
743
|
+
*/
|
|
744
|
+
class RNErrorHandlerMock {
|
|
745
|
+
onError = (error: any, isFatal: boolean) => {
|
|
746
|
+
const errorHandler = ErrorUtils.getGlobalHandler();
|
|
747
|
+
errorHandler(error, isFatal);
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
onConsoleError = (...params: any) => {
|
|
751
|
+
console.error(...params);
|
|
752
|
+
};
|
|
753
|
+
}
|