@datadog/mobile-react-native 1.5.1 → 1.6.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 +1 -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 +9 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdk.kt +4 -0
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +5 -1
- package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +4 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdLogsTest.kt +242 -2
- package/android/src/test/kotlin/com/datadog/reactnative/DdRumTest.kt +10 -0
- package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +6 -2
- package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +2 -0
- 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 +3 -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 +3 -0
- package/ios/Sources/DdRum.swift +7 -0
- package/ios/Sources/DdSdk.swift +2 -0
- package/ios/Sources/DdSdkConfiguration.swift +7 -1
- package/ios/Sources/RNDdSdkConfiguration.swift +5 -1
- package/lib/commonjs/DdSdkReactNative.js +5 -1
- package/lib/commonjs/DdSdkReactNative.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/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 +6 -0
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +60 -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.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +5 -1
- package/lib/module/DdSdkReactNative.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/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 +5 -0
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +61 -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.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/InternalLog.d.ts +1 -0
- package/lib/typescript/errorUtils.d.ts +2 -0
- 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 +44 -4
- package/lib/typescript/rum/DdRum.d.ts +1 -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 +4 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/DdSdkReactNative.tsx +6 -1
- package/src/InternalLog.tsx +3 -1
- 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 +452 -109
- package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +18 -0
- package/src/errorUtils.ts +15 -0
- 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 +73 -4
- package/src/rum/DdRum.ts +5 -0
- package/src/rum/__tests__/DdRum.test.ts +12 -27
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +41 -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 +2 -0
- package/src/types.tsx +2 -0
- package/src/version.ts +1 -1
|
@@ -4,21 +4,17 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { NativeModules } from 'react-native';
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
DdNativeLogsType,
|
|
11
|
+
DdNativeRumType
|
|
12
|
+
} from '../../../nativeModulesTypes';
|
|
8
13
|
import { DdRumErrorTracking } from '../../../rum/instrumentation/DdRumErrorTracking';
|
|
14
|
+
import { BufferSingleton } from '../../../sdk/DatadogProvider/Buffer/BufferSingleton';
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
jest.mock('../../../rum/DdRum', () => {
|
|
13
|
-
return {
|
|
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,31 @@ 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
|
+
}
|
|
88
|
+
);
|
|
77
89
|
});
|
|
78
90
|
|
|
79
91
|
it('M intercept and send a RUM event W onGlobalError() {empty stack trace}', async () => {
|
|
@@ -89,14 +101,31 @@ it('M intercept and send a RUM event W onGlobalError() {empty stack trace}', asy
|
|
|
89
101
|
await flushPromises();
|
|
90
102
|
|
|
91
103
|
// THEN
|
|
92
|
-
expect(DdRum.addError
|
|
93
|
-
expect(DdRum.addError
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
105
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
106
|
+
'Something bad happened',
|
|
107
|
+
'SOURCE',
|
|
108
|
+
'',
|
|
109
|
+
{
|
|
110
|
+
'_dd.error.raw': error,
|
|
111
|
+
'_dd.error.is_crash': is_fatal,
|
|
112
|
+
'_dd.error.source_type': 'react-native'
|
|
113
|
+
},
|
|
114
|
+
expect.any(Number)
|
|
115
|
+
);
|
|
99
116
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
117
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
118
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
119
|
+
'Something bad happened',
|
|
120
|
+
'Error',
|
|
121
|
+
'Something bad happened',
|
|
122
|
+
'',
|
|
123
|
+
{
|
|
124
|
+
'_dd.error.raw': error,
|
|
125
|
+
'_dd.error.is_crash': is_fatal,
|
|
126
|
+
'_dd.error.source_type': 'react-native'
|
|
127
|
+
}
|
|
128
|
+
);
|
|
100
129
|
});
|
|
101
130
|
|
|
102
131
|
it('M intercept and send a RUM event W onGlobalError() {Error object}', async () => {
|
|
@@ -110,19 +139,79 @@ it('M intercept and send a RUM event W onGlobalError() {Error object}', async ()
|
|
|
110
139
|
await flushPromises();
|
|
111
140
|
|
|
112
141
|
// THEN
|
|
113
|
-
expect(DdRum.addError
|
|
114
|
-
expect(DdRum.addError
|
|
115
|
-
|
|
142
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
143
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
144
|
+
'Something bad happened',
|
|
145
|
+
'SOURCE',
|
|
146
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
147
|
+
{
|
|
148
|
+
'_dd.error.raw': error,
|
|
149
|
+
'_dd.error.is_crash': is_fatal,
|
|
150
|
+
'_dd.error.source_type': 'react-native'
|
|
151
|
+
},
|
|
152
|
+
expect.any(Number)
|
|
153
|
+
);
|
|
116
154
|
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
117
|
-
'
|
|
155
|
+
'/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx'
|
|
156
|
+
);
|
|
157
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
158
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
159
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
160
|
+
'Something bad happened',
|
|
161
|
+
'Error',
|
|
162
|
+
'Something bad happened',
|
|
163
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
164
|
+
{
|
|
165
|
+
'_dd.error.raw': error,
|
|
166
|
+
'_dd.error.is_crash': is_fatal,
|
|
167
|
+
'_dd.error.source_type': 'react-native'
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('M intercept and send a RUM event W onGlobalError() {CustomError object}', async () => {
|
|
173
|
+
// GIVEN
|
|
174
|
+
class CustomError extends Error {
|
|
175
|
+
name = 'CustomError';
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
DdRumErrorTracking.startTracking();
|
|
179
|
+
const is_fatal = Math.random() < 0.5;
|
|
180
|
+
const error = new CustomError('Something bad happened');
|
|
181
|
+
|
|
182
|
+
// WHEN
|
|
183
|
+
DdRumErrorTracking.onGlobalError(error, is_fatal);
|
|
184
|
+
await flushPromises();
|
|
185
|
+
|
|
186
|
+
// THEN
|
|
187
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
188
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
189
|
+
'Something bad happened',
|
|
190
|
+
'SOURCE',
|
|
191
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
192
|
+
{
|
|
193
|
+
'_dd.error.raw': error,
|
|
194
|
+
'_dd.error.is_crash': is_fatal,
|
|
195
|
+
'_dd.error.source_type': 'react-native'
|
|
196
|
+
},
|
|
197
|
+
expect.any(Number)
|
|
118
198
|
);
|
|
119
199
|
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
120
200
|
'/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx'
|
|
121
201
|
);
|
|
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
202
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
203
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
204
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
205
|
+
'Something bad happened',
|
|
206
|
+
'CustomError',
|
|
207
|
+
'Something bad happened',
|
|
208
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
209
|
+
{
|
|
210
|
+
'_dd.error.raw': error,
|
|
211
|
+
'_dd.error.is_crash': is_fatal,
|
|
212
|
+
'_dd.error.source_type': 'react-native'
|
|
213
|
+
}
|
|
214
|
+
);
|
|
126
215
|
});
|
|
127
216
|
|
|
128
217
|
it('M intercept and send a RUM event W onGlobalError() {with source file info}', async () => {
|
|
@@ -141,16 +230,31 @@ it('M intercept and send a RUM event W onGlobalError() {with source file info}',
|
|
|
141
230
|
await flushPromises();
|
|
142
231
|
|
|
143
232
|
// THEN
|
|
144
|
-
expect(DdRum.addError
|
|
145
|
-
expect(DdRum.addError
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
'at ./path/to/file.js:1038:57'
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
233
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
234
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
235
|
+
'Something bad happened',
|
|
236
|
+
'SOURCE',
|
|
237
|
+
'at ./path/to/file.js:1038:57',
|
|
238
|
+
{
|
|
239
|
+
'_dd.error.raw': error,
|
|
240
|
+
'_dd.error.is_crash': is_fatal,
|
|
241
|
+
'_dd.error.source_type': 'react-native'
|
|
242
|
+
},
|
|
243
|
+
expect.any(Number)
|
|
244
|
+
);
|
|
153
245
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
246
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
247
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
248
|
+
'Something bad happened',
|
|
249
|
+
'Error',
|
|
250
|
+
'Something bad happened',
|
|
251
|
+
'at ./path/to/file.js:1038:57',
|
|
252
|
+
{
|
|
253
|
+
'_dd.error.raw': error,
|
|
254
|
+
'_dd.error.is_crash': is_fatal,
|
|
255
|
+
'_dd.error.source_type': 'react-native'
|
|
256
|
+
}
|
|
257
|
+
);
|
|
154
258
|
});
|
|
155
259
|
|
|
156
260
|
it('M intercept and send a RUM event W onGlobalError() {with component stack}', async () => {
|
|
@@ -171,16 +275,31 @@ it('M intercept and send a RUM event W onGlobalError() {with component stack}',
|
|
|
171
275
|
await flushPromises();
|
|
172
276
|
|
|
173
277
|
// 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
|
-
|
|
278
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
279
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
280
|
+
'Something bad happened',
|
|
281
|
+
'SOURCE',
|
|
282
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
283
|
+
{
|
|
284
|
+
'_dd.error.raw': error,
|
|
285
|
+
'_dd.error.is_crash': is_fatal,
|
|
286
|
+
'_dd.error.source_type': 'react-native'
|
|
287
|
+
},
|
|
288
|
+
expect.any(Number)
|
|
289
|
+
);
|
|
183
290
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
291
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
292
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
293
|
+
'Something bad happened',
|
|
294
|
+
'Error',
|
|
295
|
+
'Something bad happened',
|
|
296
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
297
|
+
{
|
|
298
|
+
'_dd.error.raw': error,
|
|
299
|
+
'_dd.error.is_crash': is_fatal,
|
|
300
|
+
'_dd.error.source_type': 'react-native'
|
|
301
|
+
}
|
|
302
|
+
);
|
|
184
303
|
});
|
|
185
304
|
|
|
186
305
|
it('M intercept and send a RUM event W onGlobalError() {with stack}', async () => {
|
|
@@ -201,16 +320,31 @@ it('M intercept and send a RUM event W onGlobalError() {with stack}', async () =
|
|
|
201
320
|
await flushPromises();
|
|
202
321
|
|
|
203
322
|
// 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
|
-
|
|
323
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
324
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
325
|
+
'Something bad happened',
|
|
326
|
+
'SOURCE',
|
|
327
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
328
|
+
{
|
|
329
|
+
'_dd.error.raw': error,
|
|
330
|
+
'_dd.error.is_crash': is_fatal,
|
|
331
|
+
'_dd.error.source_type': 'react-native'
|
|
332
|
+
},
|
|
333
|
+
expect.any(Number)
|
|
334
|
+
);
|
|
213
335
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
336
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
337
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
338
|
+
'Something bad happened',
|
|
339
|
+
'Error',
|
|
340
|
+
'Something bad happened',
|
|
341
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
342
|
+
{
|
|
343
|
+
'_dd.error.raw': error,
|
|
344
|
+
'_dd.error.is_crash': is_fatal,
|
|
345
|
+
'_dd.error.source_type': 'react-native'
|
|
346
|
+
}
|
|
347
|
+
);
|
|
214
348
|
});
|
|
215
349
|
|
|
216
350
|
it('M intercept and send a RUM event W onGlobalError() {with stacktrace}', async () => {
|
|
@@ -231,16 +365,32 @@ it('M intercept and send a RUM event W onGlobalError() {with stacktrace}', async
|
|
|
231
365
|
await flushPromises();
|
|
232
366
|
|
|
233
367
|
// 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
|
-
|
|
368
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
369
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
370
|
+
'Something bad happened',
|
|
371
|
+
'SOURCE',
|
|
372
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
373
|
+
{
|
|
374
|
+
'_dd.error.raw': error,
|
|
375
|
+
'_dd.error.is_crash': is_fatal,
|
|
376
|
+
'_dd.error.source_type': 'react-native'
|
|
377
|
+
},
|
|
378
|
+
expect.any(Number)
|
|
379
|
+
);
|
|
380
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
243
381
|
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
382
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
383
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
384
|
+
'Something bad happened',
|
|
385
|
+
'Error',
|
|
386
|
+
'Something bad happened',
|
|
387
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
388
|
+
{
|
|
389
|
+
'_dd.error.raw': error,
|
|
390
|
+
'_dd.error.is_crash': is_fatal,
|
|
391
|
+
'_dd.error.source_type': 'react-native'
|
|
392
|
+
}
|
|
393
|
+
);
|
|
244
394
|
});
|
|
245
395
|
|
|
246
396
|
it('M not report error in console handler W onGlobalError() {with console reporting handler}', async () => {
|
|
@@ -266,17 +416,33 @@ it('M not report error in console handler W onGlobalError() {with console report
|
|
|
266
416
|
await flushPromises();
|
|
267
417
|
|
|
268
418
|
// 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
|
-
|
|
419
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
420
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
421
|
+
'Something bad happened',
|
|
422
|
+
'SOURCE',
|
|
423
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
424
|
+
{
|
|
425
|
+
'_dd.error.raw': error,
|
|
426
|
+
'_dd.error.is_crash': is_fatal,
|
|
427
|
+
'_dd.error.source_type': 'react-native'
|
|
428
|
+
},
|
|
429
|
+
expect.any(Number)
|
|
430
|
+
);
|
|
278
431
|
expect(consoleReportingErrorHandler).toBeCalledTimes(1);
|
|
279
432
|
expect(baseConsoleErrorCalled).toStrictEqual(false);
|
|
433
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
434
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
435
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
436
|
+
'Something bad happened',
|
|
437
|
+
'Error',
|
|
438
|
+
'Something bad happened',
|
|
439
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
440
|
+
{
|
|
441
|
+
'_dd.error.raw': error,
|
|
442
|
+
'_dd.error.is_crash': is_fatal,
|
|
443
|
+
'_dd.error.source_type': 'react-native'
|
|
444
|
+
}
|
|
445
|
+
);
|
|
280
446
|
});
|
|
281
447
|
|
|
282
448
|
it('M intercept and send a RUM event W onConsole() {Error with source file info}', async () => {
|
|
@@ -295,16 +461,27 @@ it('M intercept and send a RUM event W onConsole() {Error with source file info}
|
|
|
295
461
|
await flushPromises();
|
|
296
462
|
|
|
297
463
|
// THEN
|
|
298
|
-
expect(DdRum.addError
|
|
299
|
-
expect(DdRum.addError
|
|
300
|
-
'Oops I did it again! Something bad happened'
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
464
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
465
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
466
|
+
'Oops I did it again! Something bad happened',
|
|
467
|
+
'CONSOLE',
|
|
468
|
+
'at ./path/to/file.js:1038:57',
|
|
469
|
+
{
|
|
470
|
+
'_dd.error.source_type': 'react-native'
|
|
471
|
+
},
|
|
472
|
+
expect.any(Number)
|
|
305
473
|
);
|
|
306
|
-
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
307
474
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
475
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
476
|
+
expect(
|
|
477
|
+
DdLogs.errorWithError
|
|
478
|
+
).toHaveBeenCalledWith(
|
|
479
|
+
'Oops I did it again! Something bad happened',
|
|
480
|
+
'Error',
|
|
481
|
+
'Oops I did it again! Something bad happened',
|
|
482
|
+
'at ./path/to/file.js:1038:57',
|
|
483
|
+
{ '_dd.error.source_type': 'react-native' }
|
|
484
|
+
);
|
|
308
485
|
});
|
|
309
486
|
|
|
310
487
|
it('M intercept and send a RUM event W onConsole() {Error with component stack}', async () => {
|
|
@@ -325,16 +502,27 @@ it('M intercept and send a RUM event W onConsole() {Error with component stack}'
|
|
|
325
502
|
await flushPromises();
|
|
326
503
|
|
|
327
504
|
// THEN
|
|
328
|
-
expect(DdRum.addError
|
|
329
|
-
expect(DdRum.addError
|
|
330
|
-
'Oops I did it again! Something bad happened'
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
505
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
506
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
507
|
+
'Oops I did it again! Something bad happened',
|
|
508
|
+
'CONSOLE',
|
|
509
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
510
|
+
{
|
|
511
|
+
'_dd.error.source_type': 'react-native'
|
|
512
|
+
},
|
|
513
|
+
expect.any(Number)
|
|
335
514
|
);
|
|
336
|
-
expect(DdRum.addError.mock.calls[0][3]).toBeUndefined();
|
|
337
515
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
516
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
517
|
+
expect(
|
|
518
|
+
DdLogs.errorWithError
|
|
519
|
+
).toHaveBeenCalledWith(
|
|
520
|
+
'Oops I did it again! Something bad happened',
|
|
521
|
+
'Error',
|
|
522
|
+
'Oops I did it again! Something bad happened',
|
|
523
|
+
'doSomething() at ./path/to/file.js:67:3,nestedCall() at ./path/to/file.js:1064:9,root() at ./path/to/index.js:10:1',
|
|
524
|
+
{ '_dd.error.source_type': 'react-native' }
|
|
525
|
+
);
|
|
338
526
|
});
|
|
339
527
|
|
|
340
528
|
it('M intercept and send a RUM event W onConsole() {message only}', async () => {
|
|
@@ -347,12 +535,65 @@ it('M intercept and send a RUM event W onConsole() {message only}', async () =>
|
|
|
347
535
|
await flushPromises();
|
|
348
536
|
|
|
349
537
|
// THEN
|
|
350
|
-
expect(DdRum.addError
|
|
351
|
-
expect(DdRum.addError
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
538
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
539
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
540
|
+
message,
|
|
541
|
+
'CONSOLE',
|
|
542
|
+
'',
|
|
543
|
+
{
|
|
544
|
+
'_dd.error.source_type': 'react-native'
|
|
545
|
+
},
|
|
546
|
+
expect.any(Number)
|
|
547
|
+
);
|
|
548
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
549
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
550
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
551
|
+
'Something bad happened',
|
|
552
|
+
'Error',
|
|
553
|
+
'Something bad happened',
|
|
554
|
+
'',
|
|
555
|
+
{ '_dd.error.source_type': 'react-native' }
|
|
556
|
+
);
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
it('M intercept and send a RUM event W onConsole() {Error with source file and name}', async () => {
|
|
560
|
+
// GIVEN
|
|
561
|
+
DdRumErrorTracking.startTracking();
|
|
562
|
+
const message = 'Oops I did it again!';
|
|
563
|
+
const error = {
|
|
564
|
+
sourceURL: './path/to/file.js',
|
|
565
|
+
line: 1038,
|
|
566
|
+
column: 57,
|
|
567
|
+
message: 'Something bad happened',
|
|
568
|
+
name: 'CustomConsoleError'
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
// WHEN
|
|
572
|
+
DdRumErrorTracking.onConsoleError(message, error);
|
|
573
|
+
await flushPromises();
|
|
574
|
+
|
|
575
|
+
// THEN
|
|
576
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
577
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
578
|
+
'Oops I did it again! Something bad happened',
|
|
579
|
+
'CONSOLE',
|
|
580
|
+
'at ./path/to/file.js:1038:57',
|
|
581
|
+
{
|
|
582
|
+
'_dd.error.source_type': 'react-native'
|
|
583
|
+
},
|
|
584
|
+
expect.any(Number)
|
|
585
|
+
);
|
|
355
586
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
587
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
588
|
+
expect(
|
|
589
|
+
DdLogs.errorWithError
|
|
590
|
+
).toHaveBeenCalledWith(
|
|
591
|
+
'Oops I did it again! Something bad happened',
|
|
592
|
+
'CustomConsoleError',
|
|
593
|
+
'Oops I did it again! Something bad happened',
|
|
594
|
+
'at ./path/to/file.js:1038:57',
|
|
595
|
+
{ '_dd.error.source_type': 'react-native' }
|
|
596
|
+
);
|
|
356
597
|
});
|
|
357
598
|
|
|
358
599
|
describe.each([
|
|
@@ -374,15 +615,117 @@ describe.each([
|
|
|
374
615
|
await flushPromises();
|
|
375
616
|
|
|
376
617
|
// THEN
|
|
377
|
-
|
|
378
|
-
expect(DdRum.addError.mock.calls[0][0]).toBe(
|
|
618
|
+
const errorMessage =
|
|
379
619
|
message === undefined || message === null
|
|
380
620
|
? 'Unknown Error'
|
|
381
|
-
: String(message)
|
|
621
|
+
: String(message);
|
|
622
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
623
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
624
|
+
errorMessage,
|
|
625
|
+
'CONSOLE',
|
|
626
|
+
'',
|
|
627
|
+
{
|
|
628
|
+
'_dd.error.source_type': 'react-native'
|
|
629
|
+
},
|
|
630
|
+
expect.any(Number)
|
|
382
631
|
);
|
|
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
632
|
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
633
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
634
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
635
|
+
errorMessage,
|
|
636
|
+
'Error',
|
|
637
|
+
errorMessage,
|
|
638
|
+
'',
|
|
639
|
+
{ '_dd.error.source_type': 'react-native' }
|
|
640
|
+
);
|
|
387
641
|
});
|
|
388
642
|
});
|
|
643
|
+
|
|
644
|
+
it('M intercept and send a RUM event W on error() {called from RNErrorHandler}', async () => {
|
|
645
|
+
// GIVEN
|
|
646
|
+
const errorHandlerMock = new RNErrorHandlerMock();
|
|
647
|
+
DdRumErrorTracking.startTracking();
|
|
648
|
+
const is_fatal = Math.random() < 0.5;
|
|
649
|
+
const error = new Error('Something bad happened');
|
|
650
|
+
|
|
651
|
+
// WHEN
|
|
652
|
+
errorHandlerMock.onError(error, is_fatal);
|
|
653
|
+
await flushPromises();
|
|
654
|
+
|
|
655
|
+
// THEN
|
|
656
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
657
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
658
|
+
'Something bad happened',
|
|
659
|
+
'SOURCE',
|
|
660
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
661
|
+
{
|
|
662
|
+
'_dd.error.raw': error,
|
|
663
|
+
'_dd.error.is_crash': is_fatal,
|
|
664
|
+
'_dd.error.source_type': 'react-native'
|
|
665
|
+
},
|
|
666
|
+
expect.any(Number)
|
|
667
|
+
);
|
|
668
|
+
expect(DdRum.addError.mock.calls[0][2]).toContain(
|
|
669
|
+
'/packages/core/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx'
|
|
670
|
+
);
|
|
671
|
+
expect(baseErrorHandlerCalled).toStrictEqual(true);
|
|
672
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
673
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
674
|
+
'Something bad happened',
|
|
675
|
+
'Error',
|
|
676
|
+
'Something bad happened',
|
|
677
|
+
expect.stringContaining('Error: Something bad happened'),
|
|
678
|
+
{
|
|
679
|
+
'_dd.error.raw': error,
|
|
680
|
+
'_dd.error.is_crash': is_fatal,
|
|
681
|
+
'_dd.error.source_type': 'react-native'
|
|
682
|
+
}
|
|
683
|
+
);
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
it('M intercept and send a RUM event W onConsole() {called from RNErrorHandler}', async () => {
|
|
687
|
+
// GIVEN
|
|
688
|
+
const errorHandlerMock = new RNErrorHandlerMock();
|
|
689
|
+
DdRumErrorTracking.startTracking();
|
|
690
|
+
const message = 'Oops I did it again!';
|
|
691
|
+
|
|
692
|
+
// WHEN
|
|
693
|
+
errorHandlerMock.onConsoleError(message);
|
|
694
|
+
await flushPromises();
|
|
695
|
+
|
|
696
|
+
// THEN
|
|
697
|
+
expect(DdRum.addError).toHaveBeenCalledTimes(1);
|
|
698
|
+
expect(DdRum.addError).toHaveBeenCalledWith(
|
|
699
|
+
'Oops I did it again!',
|
|
700
|
+
'CONSOLE',
|
|
701
|
+
'',
|
|
702
|
+
{
|
|
703
|
+
'_dd.error.source_type': 'react-native'
|
|
704
|
+
},
|
|
705
|
+
expect.any(Number)
|
|
706
|
+
);
|
|
707
|
+
expect(baseConsoleErrorCalled).toStrictEqual(true);
|
|
708
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledTimes(1);
|
|
709
|
+
expect(DdLogs.errorWithError).toHaveBeenCalledWith(
|
|
710
|
+
'Oops I did it again!',
|
|
711
|
+
'Error',
|
|
712
|
+
'Oops I did it again!',
|
|
713
|
+
'',
|
|
714
|
+
{ '_dd.error.source_type': 'react-native' }
|
|
715
|
+
);
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* This is a mock of the RN error handler class that will call the ErrorUtils.
|
|
720
|
+
* Testing with this catches bugs around `this` references.
|
|
721
|
+
*/
|
|
722
|
+
class RNErrorHandlerMock {
|
|
723
|
+
onError = (error: any, isFatal: boolean) => {
|
|
724
|
+
const errorHandler = ErrorUtils.getGlobalHandler();
|
|
725
|
+
errorHandler(error, isFatal);
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
onConsoleError = (...params: any) => {
|
|
729
|
+
console.error(...params);
|
|
730
|
+
};
|
|
731
|
+
}
|