@datadog/mobile-react-native 2.3.5 → 2.3.6
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/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +1 -1
- package/datadog-sourcemaps.gradle +64 -1
- package/ios/Sources/SdkVersion.swift +1 -1
- package/lib/commonjs/logs/DdLogs.js +10 -8
- package/lib/commonjs/logs/DdLogs.js.map +1 -1
- package/lib/commonjs/rum/DdRum.js +50 -48
- package/lib/commonjs/rum/DdRum.js.map +1 -1
- package/lib/commonjs/trace/DdTrace.js +4 -2
- package/lib/commonjs/trace/DdTrace.js.map +1 -1
- package/lib/commonjs/utils/argsUtils.js +43 -0
- package/lib/commonjs/utils/argsUtils.js.map +1 -0
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/logs/DdLogs.js +9 -8
- package/lib/module/logs/DdLogs.js.map +1 -1
- package/lib/module/rum/DdRum.js +48 -47
- package/lib/module/rum/DdRum.js.map +1 -1
- package/lib/module/trace/DdTrace.js +3 -2
- package/lib/module/trace/DdTrace.js.map +1 -1
- package/lib/module/utils/argsUtils.js +30 -0
- package/lib/module/utils/argsUtils.js.map +1 -0
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/rum/DdRum.d.ts +2 -2
- package/lib/typescript/utils/argsUtils.d.ts +1 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/logs/DdLogs.ts +9 -8
- package/src/logs/__tests__/DdLogs.test.ts +543 -0
- package/src/rum/DdRum.ts +112 -94
- package/src/rum/__tests__/DdRum.test.ts +552 -0
- package/src/trace/DdTrace.ts +12 -2
- package/src/trace/__tests__/DdTrace.test.ts +146 -0
- package/src/utils/__tests__/argsUtils.test.ts +66 -0
- package/src/utils/argsUtils.ts +35 -0
- package/src/version.ts +1 -1
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
import { NativeModules } from 'react-native';
|
|
9
9
|
|
|
10
10
|
import { DdSdkReactNative } from '../../DdSdkReactNative';
|
|
11
|
+
import { InternalLog } from '../../InternalLog';
|
|
12
|
+
import { SdkVerbosity } from '../../SdkVerbosity';
|
|
11
13
|
import { BufferSingleton } from '../../sdk/DatadogProvider/Buffer/BufferSingleton';
|
|
12
14
|
import { DdSdk } from '../../sdk/DdSdk';
|
|
13
15
|
import { DdRum } from '../DdRum';
|
|
@@ -24,12 +26,562 @@ jest.mock('../../utils/time-provider/DefaultTimeProvider', () => {
|
|
|
24
26
|
};
|
|
25
27
|
});
|
|
26
28
|
|
|
29
|
+
jest.mock('../../InternalLog', () => {
|
|
30
|
+
return {
|
|
31
|
+
InternalLog: {
|
|
32
|
+
log: jest.fn()
|
|
33
|
+
},
|
|
34
|
+
DATADOG_MESSAGE_PREFIX: 'DATADOG:'
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
27
38
|
describe('DdRum', () => {
|
|
28
39
|
beforeEach(() => {
|
|
29
40
|
jest.clearAllMocks();
|
|
30
41
|
BufferSingleton.onInitialization();
|
|
31
42
|
});
|
|
32
43
|
|
|
44
|
+
describe('Context validation', () => {
|
|
45
|
+
describe('DdRum.startView', () => {
|
|
46
|
+
test('uses given context when context is valid', async () => {
|
|
47
|
+
const context = {
|
|
48
|
+
testA: 123,
|
|
49
|
+
testB: 'ok'
|
|
50
|
+
};
|
|
51
|
+
await DdRum.startView('key', 'name', context);
|
|
52
|
+
|
|
53
|
+
expect(NativeModules.DdRum.startView).toHaveBeenCalledWith(
|
|
54
|
+
expect.anything(),
|
|
55
|
+
expect.anything(),
|
|
56
|
+
context,
|
|
57
|
+
expect.anything()
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
62
|
+
const context: any = 123;
|
|
63
|
+
await DdRum.startView('key', 'name', context);
|
|
64
|
+
|
|
65
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
66
|
+
2,
|
|
67
|
+
expect.anything(),
|
|
68
|
+
SdkVerbosity.ERROR
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(NativeModules.DdRum.startView).toHaveBeenCalledWith(
|
|
72
|
+
expect.anything(),
|
|
73
|
+
expect.anything(),
|
|
74
|
+
{},
|
|
75
|
+
expect.anything()
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('nests given context in new object when context is array', async () => {
|
|
80
|
+
const context: any = [123, '456'];
|
|
81
|
+
await DdRum.startView('key', 'name', context);
|
|
82
|
+
|
|
83
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
84
|
+
2,
|
|
85
|
+
expect.anything(),
|
|
86
|
+
SdkVerbosity.WARN
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect(NativeModules.DdRum.startView).toHaveBeenCalledWith(
|
|
90
|
+
expect.anything(),
|
|
91
|
+
expect.anything(),
|
|
92
|
+
{ context },
|
|
93
|
+
expect.anything()
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('DdRum.stopView', () => {
|
|
99
|
+
test('uses given context when context is valid', async () => {
|
|
100
|
+
const context = {
|
|
101
|
+
testA: 123,
|
|
102
|
+
testB: 'ok'
|
|
103
|
+
};
|
|
104
|
+
await DdRum.startView('key', 'name');
|
|
105
|
+
await DdRum.stopView('key', context);
|
|
106
|
+
|
|
107
|
+
expect(NativeModules.DdRum.stopView).toHaveBeenCalledWith(
|
|
108
|
+
'key',
|
|
109
|
+
context,
|
|
110
|
+
expect.anything()
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
115
|
+
const context: any = 123;
|
|
116
|
+
|
|
117
|
+
await DdRum.startView('key', 'name');
|
|
118
|
+
await DdRum.stopView('key', context);
|
|
119
|
+
|
|
120
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
121
|
+
3,
|
|
122
|
+
expect.anything(),
|
|
123
|
+
SdkVerbosity.ERROR
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(NativeModules.DdRum.stopView).toHaveBeenCalledWith(
|
|
127
|
+
'key',
|
|
128
|
+
{},
|
|
129
|
+
expect.anything()
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('nests given context in new object when context is array', async () => {
|
|
134
|
+
const context: any = [123, '456'];
|
|
135
|
+
|
|
136
|
+
await DdRum.startView('key', 'name');
|
|
137
|
+
await DdRum.stopView('key', context);
|
|
138
|
+
|
|
139
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
140
|
+
3,
|
|
141
|
+
expect.anything(),
|
|
142
|
+
SdkVerbosity.WARN
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
expect(NativeModules.DdRum.stopView).toHaveBeenCalledWith(
|
|
146
|
+
'key',
|
|
147
|
+
{ context },
|
|
148
|
+
expect.anything()
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('DdRum.startAction', () => {
|
|
154
|
+
test('uses given context when context is valid', async () => {
|
|
155
|
+
const context = {
|
|
156
|
+
testA: 123,
|
|
157
|
+
testB: 'ok'
|
|
158
|
+
};
|
|
159
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name', context);
|
|
160
|
+
|
|
161
|
+
expect(NativeModules.DdRum.startAction).toHaveBeenCalledWith(
|
|
162
|
+
expect.anything(),
|
|
163
|
+
expect.anything(),
|
|
164
|
+
context,
|
|
165
|
+
expect.anything()
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
170
|
+
const context: any = 123;
|
|
171
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name', context);
|
|
172
|
+
|
|
173
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
174
|
+
2,
|
|
175
|
+
expect.anything(),
|
|
176
|
+
SdkVerbosity.ERROR
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(NativeModules.DdRum.startAction).toHaveBeenCalledWith(
|
|
180
|
+
expect.anything(),
|
|
181
|
+
expect.anything(),
|
|
182
|
+
{},
|
|
183
|
+
expect.anything()
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('nests given context in new object when context is array', async () => {
|
|
188
|
+
const context: any = [123, '456'];
|
|
189
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name', context);
|
|
190
|
+
|
|
191
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
192
|
+
2,
|
|
193
|
+
expect.anything(),
|
|
194
|
+
SdkVerbosity.WARN
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
expect(NativeModules.DdRum.startAction).toHaveBeenCalledWith(
|
|
198
|
+
expect.anything(),
|
|
199
|
+
expect.anything(),
|
|
200
|
+
{ context },
|
|
201
|
+
expect.anything()
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('DdRum.stopAction', () => {
|
|
207
|
+
describe('New API', () => {
|
|
208
|
+
test('uses given context when context is valid', async () => {
|
|
209
|
+
const context = {
|
|
210
|
+
testA: 123,
|
|
211
|
+
testB: 'ok'
|
|
212
|
+
};
|
|
213
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name');
|
|
214
|
+
await DdRum.stopAction(
|
|
215
|
+
RumActionType.SCROLL,
|
|
216
|
+
'name',
|
|
217
|
+
context
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
221
|
+
RumActionType.SCROLL,
|
|
222
|
+
'name',
|
|
223
|
+
context,
|
|
224
|
+
expect.anything()
|
|
225
|
+
);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
229
|
+
const context: any = 123;
|
|
230
|
+
|
|
231
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name');
|
|
232
|
+
await DdRum.stopAction(
|
|
233
|
+
RumActionType.SCROLL,
|
|
234
|
+
'name',
|
|
235
|
+
context
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
239
|
+
3,
|
|
240
|
+
expect.anything(),
|
|
241
|
+
SdkVerbosity.ERROR
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
245
|
+
RumActionType.SCROLL,
|
|
246
|
+
'name',
|
|
247
|
+
{},
|
|
248
|
+
expect.anything()
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('nests given context in new object when context is array', async () => {
|
|
253
|
+
const context: any = [123, '456'];
|
|
254
|
+
|
|
255
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name');
|
|
256
|
+
await DdRum.stopAction(
|
|
257
|
+
RumActionType.SCROLL,
|
|
258
|
+
'name',
|
|
259
|
+
context
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
263
|
+
3,
|
|
264
|
+
expect.anything(),
|
|
265
|
+
SdkVerbosity.WARN
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
269
|
+
RumActionType.SCROLL,
|
|
270
|
+
'name',
|
|
271
|
+
{ context },
|
|
272
|
+
expect.anything()
|
|
273
|
+
);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('Old API', () => {
|
|
278
|
+
test('uses given context when context is valid', async () => {
|
|
279
|
+
const context = {
|
|
280
|
+
testA: 123,
|
|
281
|
+
testB: 'ok'
|
|
282
|
+
};
|
|
283
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name');
|
|
284
|
+
await DdRum.stopAction(context);
|
|
285
|
+
|
|
286
|
+
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
287
|
+
RumActionType.SCROLL,
|
|
288
|
+
'name',
|
|
289
|
+
context,
|
|
290
|
+
expect.anything()
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
295
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name');
|
|
296
|
+
await DdRum.stopAction(undefined);
|
|
297
|
+
|
|
298
|
+
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
299
|
+
RumActionType.SCROLL,
|
|
300
|
+
'name',
|
|
301
|
+
{},
|
|
302
|
+
expect.anything()
|
|
303
|
+
);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('nests given context in new object when context is array', async () => {
|
|
307
|
+
const context: any = [123, '456'];
|
|
308
|
+
|
|
309
|
+
await DdRum.startAction(RumActionType.SCROLL, 'name');
|
|
310
|
+
await DdRum.stopAction(context);
|
|
311
|
+
|
|
312
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
313
|
+
3,
|
|
314
|
+
expect.anything(),
|
|
315
|
+
SdkVerbosity.WARN
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
expect(NativeModules.DdRum.stopAction).toHaveBeenCalledWith(
|
|
319
|
+
RumActionType.SCROLL,
|
|
320
|
+
'name',
|
|
321
|
+
{ context },
|
|
322
|
+
expect.anything()
|
|
323
|
+
);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('DdRum.startResource', () => {
|
|
329
|
+
test('uses given context when context is valid', async () => {
|
|
330
|
+
const context = {
|
|
331
|
+
testA: 123,
|
|
332
|
+
testB: 'ok'
|
|
333
|
+
};
|
|
334
|
+
await DdRum.startResource('key', 'method', 'url', context);
|
|
335
|
+
|
|
336
|
+
expect(NativeModules.DdRum.startResource).toHaveBeenCalledWith(
|
|
337
|
+
'key',
|
|
338
|
+
'method',
|
|
339
|
+
'url',
|
|
340
|
+
context,
|
|
341
|
+
expect.anything()
|
|
342
|
+
);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
346
|
+
const context: any = 123;
|
|
347
|
+
|
|
348
|
+
await DdRum.startResource('key', 'method', 'url', context);
|
|
349
|
+
|
|
350
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
351
|
+
2,
|
|
352
|
+
expect.anything(),
|
|
353
|
+
SdkVerbosity.ERROR
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
expect(NativeModules.DdRum.startResource).toHaveBeenCalledWith(
|
|
357
|
+
'key',
|
|
358
|
+
'method',
|
|
359
|
+
'url',
|
|
360
|
+
{},
|
|
361
|
+
expect.anything()
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test('nests given context in new object when context is array', async () => {
|
|
366
|
+
const context: any = [123, '456'];
|
|
367
|
+
|
|
368
|
+
await DdRum.startResource('key', 'method', 'url', context);
|
|
369
|
+
|
|
370
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
371
|
+
2,
|
|
372
|
+
expect.anything(),
|
|
373
|
+
SdkVerbosity.WARN
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
expect(NativeModules.DdRum.startResource).toHaveBeenCalledWith(
|
|
377
|
+
'key',
|
|
378
|
+
'method',
|
|
379
|
+
'url',
|
|
380
|
+
{ context },
|
|
381
|
+
expect.anything()
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe('DdRum.stopResource', () => {
|
|
387
|
+
test('uses given context when context is valid', async () => {
|
|
388
|
+
const context = {
|
|
389
|
+
testA: 123,
|
|
390
|
+
testB: 'ok'
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
await DdRum.startResource('key', 'method', 'url', {});
|
|
394
|
+
await DdRum.stopResource('key', 200, 'other', -1, context);
|
|
395
|
+
|
|
396
|
+
expect(NativeModules.DdRum.stopResource).toHaveBeenCalledWith(
|
|
397
|
+
'key',
|
|
398
|
+
200,
|
|
399
|
+
'other',
|
|
400
|
+
-1,
|
|
401
|
+
context,
|
|
402
|
+
expect.anything()
|
|
403
|
+
);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
407
|
+
const context: any = 123;
|
|
408
|
+
|
|
409
|
+
await DdRum.startResource('key', 'method', 'url', {});
|
|
410
|
+
await DdRum.stopResource('key', 200, 'other', -1, context);
|
|
411
|
+
|
|
412
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
413
|
+
2,
|
|
414
|
+
expect.anything(),
|
|
415
|
+
SdkVerbosity.ERROR
|
|
416
|
+
);
|
|
417
|
+
|
|
418
|
+
expect(NativeModules.DdRum.stopResource).toHaveBeenCalledWith(
|
|
419
|
+
'key',
|
|
420
|
+
200,
|
|
421
|
+
'other',
|
|
422
|
+
-1,
|
|
423
|
+
{},
|
|
424
|
+
expect.anything()
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test('nests given context in new object when context is array', async () => {
|
|
429
|
+
const context: any = [123, '456'];
|
|
430
|
+
|
|
431
|
+
await DdRum.startResource('key', 'method', 'url', {});
|
|
432
|
+
await DdRum.stopResource('key', 200, 'other', -1, context);
|
|
433
|
+
|
|
434
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
435
|
+
2,
|
|
436
|
+
expect.anything(),
|
|
437
|
+
SdkVerbosity.WARN
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
expect(NativeModules.DdRum.stopResource).toHaveBeenCalledWith(
|
|
441
|
+
'key',
|
|
442
|
+
200,
|
|
443
|
+
'other',
|
|
444
|
+
-1,
|
|
445
|
+
{ context },
|
|
446
|
+
expect.anything()
|
|
447
|
+
);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
describe('DdRum.addAction', () => {
|
|
452
|
+
test('uses given context when context is valid', async () => {
|
|
453
|
+
const context = {
|
|
454
|
+
testA: 123,
|
|
455
|
+
testB: 'ok'
|
|
456
|
+
};
|
|
457
|
+
await DdRum.addAction(RumActionType.SCROLL, 'name', context);
|
|
458
|
+
|
|
459
|
+
expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
|
|
460
|
+
expect.anything(),
|
|
461
|
+
expect.anything(),
|
|
462
|
+
context,
|
|
463
|
+
expect.anything()
|
|
464
|
+
);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
468
|
+
const context: any = 123;
|
|
469
|
+
await DdRum.addAction(RumActionType.SCROLL, 'name', context);
|
|
470
|
+
|
|
471
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
472
|
+
1,
|
|
473
|
+
expect.anything(),
|
|
474
|
+
SdkVerbosity.ERROR
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
|
|
478
|
+
expect.anything(),
|
|
479
|
+
expect.anything(),
|
|
480
|
+
{},
|
|
481
|
+
expect.anything()
|
|
482
|
+
);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test('nests given context in new object when context is array', async () => {
|
|
486
|
+
const context: any = [123, '456'];
|
|
487
|
+
await DdRum.addAction(RumActionType.SCROLL, 'name', context);
|
|
488
|
+
|
|
489
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
490
|
+
1,
|
|
491
|
+
expect.anything(),
|
|
492
|
+
SdkVerbosity.WARN
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
expect(NativeModules.DdRum.addAction).toHaveBeenCalledWith(
|
|
496
|
+
expect.anything(),
|
|
497
|
+
expect.anything(),
|
|
498
|
+
{ context },
|
|
499
|
+
expect.anything()
|
|
500
|
+
);
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
describe('DdRum.addError', () => {
|
|
505
|
+
test('uses given context when context is valid', async () => {
|
|
506
|
+
const context = {
|
|
507
|
+
testA: 123,
|
|
508
|
+
testB: 'ok'
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
await DdRum.addError(
|
|
512
|
+
'error',
|
|
513
|
+
ErrorSource.CUSTOM,
|
|
514
|
+
'stacktrace',
|
|
515
|
+
context
|
|
516
|
+
);
|
|
517
|
+
|
|
518
|
+
expect(NativeModules.DdRum.addError).toHaveBeenCalledWith(
|
|
519
|
+
'error',
|
|
520
|
+
ErrorSource.CUSTOM,
|
|
521
|
+
'stacktrace',
|
|
522
|
+
{
|
|
523
|
+
...context,
|
|
524
|
+
'_dd.error.source_type': 'react-native'
|
|
525
|
+
},
|
|
526
|
+
expect.anything()
|
|
527
|
+
);
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
test('uses empty context with error when context is invalid or null', async () => {
|
|
531
|
+
const context: any = 123;
|
|
532
|
+
await DdRum.addError(
|
|
533
|
+
'error',
|
|
534
|
+
ErrorSource.CUSTOM,
|
|
535
|
+
'stacktrace',
|
|
536
|
+
context
|
|
537
|
+
);
|
|
538
|
+
|
|
539
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
540
|
+
1,
|
|
541
|
+
expect.anything(),
|
|
542
|
+
SdkVerbosity.ERROR
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
expect(NativeModules.DdRum.addError).toHaveBeenCalledWith(
|
|
546
|
+
'error',
|
|
547
|
+
ErrorSource.CUSTOM,
|
|
548
|
+
'stacktrace',
|
|
549
|
+
{
|
|
550
|
+
'_dd.error.source_type': 'react-native'
|
|
551
|
+
},
|
|
552
|
+
expect.anything()
|
|
553
|
+
);
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
test('nests given context in new object when context is array', async () => {
|
|
557
|
+
const context: any = [123, '456'];
|
|
558
|
+
await DdRum.addError(
|
|
559
|
+
'error',
|
|
560
|
+
ErrorSource.CUSTOM,
|
|
561
|
+
'stacktrace',
|
|
562
|
+
context
|
|
563
|
+
);
|
|
564
|
+
|
|
565
|
+
expect(InternalLog.log).toHaveBeenNthCalledWith(
|
|
566
|
+
1,
|
|
567
|
+
expect.anything(),
|
|
568
|
+
SdkVerbosity.WARN
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
expect(NativeModules.DdRum.addError).toHaveBeenCalledWith(
|
|
572
|
+
'error',
|
|
573
|
+
ErrorSource.CUSTOM,
|
|
574
|
+
'stacktrace',
|
|
575
|
+
{
|
|
576
|
+
context,
|
|
577
|
+
'_dd.error.source_type': 'react-native'
|
|
578
|
+
},
|
|
579
|
+
expect.anything()
|
|
580
|
+
);
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
|
|
33
585
|
describe('DdRum.stopAction', () => {
|
|
34
586
|
test('calls the native SDK when called with new API', async () => {
|
|
35
587
|
await DdRum.stopAction(
|
package/src/trace/DdTrace.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
bufferNativeCallWithId
|
|
13
13
|
} from '../sdk/DatadogProvider/Buffer/bufferNativeCall';
|
|
14
14
|
import type { DdTraceType } from '../types';
|
|
15
|
+
import { validateContext } from '../utils/argsUtils';
|
|
15
16
|
import { DefaultTimeProvider } from '../utils/time-provider/DefaultTimeProvider';
|
|
16
17
|
|
|
17
18
|
const timeProvider = new DefaultTimeProvider();
|
|
@@ -27,7 +28,11 @@ class DdTraceWrapper implements DdTraceType {
|
|
|
27
28
|
timestampMs: number = timeProvider.now()
|
|
28
29
|
): Promise<string> => {
|
|
29
30
|
const spanId = bufferNativeCallReturningId(() =>
|
|
30
|
-
this.nativeTrace.startSpan(
|
|
31
|
+
this.nativeTrace.startSpan(
|
|
32
|
+
operation,
|
|
33
|
+
validateContext(context),
|
|
34
|
+
timestampMs
|
|
35
|
+
)
|
|
31
36
|
);
|
|
32
37
|
InternalLog.log(
|
|
33
38
|
`Starting span “${operation}” #${spanId}`,
|
|
@@ -43,7 +48,12 @@ class DdTraceWrapper implements DdTraceType {
|
|
|
43
48
|
): Promise<void> => {
|
|
44
49
|
InternalLog.log(`Finishing span #${spanId}`, SdkVerbosity.DEBUG);
|
|
45
50
|
return bufferNativeCallWithId(
|
|
46
|
-
id =>
|
|
51
|
+
id =>
|
|
52
|
+
this.nativeTrace.finishSpan(
|
|
53
|
+
id,
|
|
54
|
+
validateContext(context),
|
|
55
|
+
timestampMs
|
|
56
|
+
),
|
|
47
57
|
spanId
|
|
48
58
|
);
|
|
49
59
|
};
|